CSS link in html - hyperlink

I'm linking to a css file in html but it doesn't seem to apply.
/style.css" rel="stylesheet">
html is complaining on the second < as if it wouldn't be closed and is marked red. Anyone who know's anything about this issue?

The CSS link in an HTML page you have to do it like this
<link rel="stylesheet" href="style.css" /> provided that the HTML and CSS file are in the same folder

Related

Render HTML file with CSS and local variables

I have the following content in an HTML file placed under public/company/ with a CSS file css/style.css:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"/>
</head>
<body>
<div class="title">Name {name}</div>
</body>
</html>
I want to render this HTML file with the CSS stylesheet from an action and replace {name} without changing the physical file content and place. I can render the HTML file but the CSS file would not be found. Can anyone help me render the HTML file with the CSS file and replace the {name}?
css/style.css when called from company/file.html will try to load company/css/style.css.
Click here to see an article the way you can do that. Hope it will help!
But, I'm not sure why you are looking to render that way where Rails has all the features in place.
If your CSS file is located at /public/company/css/style.css, then your static HTML file should link it with an absolute path. Use a leading / in the resource's path indicate an absolute path.:
<link href="/company/css/style.css" rel="stylesheet" type="text/css" media="all"/>
Note that the Rails router will likely catch this request and raise an exception. Depending on the web server, you may need to enable static assets or serve directly, bypassing Rails altogether.
Changing the content of a static HTML file server-side without actually modifying it (ie. adding ERb) isn't straightforward. You could:
inject some javascript into the response to perform modifications client-side. (ugly)
load the static HTML file using Nokogiri, et. al., modify the content, and send the output to the client. (expensive)
Sounds to me like these vanilla HTML/CSS files are third party (designer? client?) and you would like to drop it in /public and have it work automatically with Rails. That would be nice, but it's not that easy. You'd be better off using Rails' built-in templating system, but that means modifying files and moving them to the expected locations.

ASP.NET MVC: how to append a token to CSS URL properly?

I can append a token to my script references like this:
<script type="text/javascript" src="/Some.js?<%= Html.GetToken() %>"></script>
... and this works fine. But, if I try to append the same token the same way to a CSS file reference:
<link rel="stylesheet" type="text/css" href="/Some.css?<%= Html.GetToken() %>" />
... the IIS generates the following markup:
<link rel="stylesheet" type="text/css" href="/Some.css?<%= Html.GetToken() %>" />
I know I'm missing something super simple but I cannot see what exactly. Thanks in advance for any help!
This happens if your <head> section has runat="server". If you can live without it (in ASP.NET MVC you usually can) try it this way.
If not, add or modify the CSS link in your view's Page_Load. If that sounds awful to you, then removing runat="server" should be working :)
There a trick you can use for auto versioning.
Check out the post here:
Auto-versioning in ASP.NET MVC for CSS / JS Files?

wicked_pdf does not include styles

I used
<%= wicked_pdf_stylesheet_link_tag "pdf" %>
it shows the following output in the html
<link href="/stylesheets/pdf.css?1302860585" media="screen" rel="stylesheet" type="text/css">
<link href="file:///home/likewise-open/NEXTBRIDGE/nazar.hussain/osd/development/atlantis/public/stylesheets/pdf" media="screen" rel="stylesheet" type="text/css">
But when create the pdf it do not have any style. If i copy all css from the file to the header of the page, it includes all styles. What is the issue and how to solve it.
I personally haven't had any trouble with this method, but I've seen others that have.
I just pushed some updates to the main project that should resolve this issue for you.
wicked_pdf_stylesheet_link_tag now will inline any css files passed in directly into the markup.
I also updated the Github issue you created.

Can't get CSS loaded in Master page

So I am trying to simply load a .css file from within the master page.
The master page Admin.Master and the css file AdminView.css are both in the /views/shared folder. I am sticking the following link tag in the section of my Master page.
I have tried both:
<link href="<%: ResolveUrl("AdminView.css")%>" rel="stylesheet" type="text/css"/>
and
<link href="AdminView.css" rel="stylesheet" type="text/css"/>
As well as every other combination (~/views/shared/adminview.css OR /adminview.css....etc)
and when viewing in Firebug what it loads, it always returns "Resource not found".
NOTE: I have double checked the name and spelling.
Its these trival stuff that shouldn't be this difficult.
You can't access resources in the Views folder directly from the web. You should put your content in the Content folder (or Content/Styles) and reference it from there. The Views folder is for the framework to use to find your Views, it isn't visible from the web.
<link href="<%: Url.Content( "~/content/styles/adminview.css" ) %>" ... />
<link href="/views/shared/AdminView.css" rel="stylesheet" type="text/css"/>

Can't get CSS to load

I can't seem to get a css file to apply its styling to a form. It is quite frustrating now because as far as I know it should work!
In my head I have
<link href="/stylesheets/formtastic.css?1290524609" media="screen" rel="stylesheet" type="text/css" />
and in the body I have:
<form action="/agents" class="formtastic agent" id="new_agent" method="post">
The formtastic.css file should apply styling to the form. It's contents are viewable here:
formtastic.css
Any suggestions or fixes?
The problem was that the following code was not inserted in the form:
<% f.inputs do %>
This creates the html and now the css works.
i.e. the html missing was
dont you need to turn that number into a querysting var?
<link href="/stylesheets/formtastic.css?math=1290524609" media="screen" rel="stylesheet" type="text/css" />
Are you using this with Rails? If so, you could simply put this in your header:
<%= formtastic_stylesheet_link_tag %>
Also, have you run both bundle install and rails generate formtastic:install (for Rails 3, use ./script/generate formtastic for Rails 2)?
Are you sure the path is correct? if you check source with firebug check the link tag and see if its contents are a 404 error. It may be an issue with your root-relative path.
This is only a guess as I can't see how your site is structured.
Are you sure you have to begin with a forward slash ? (/)
Cause it's mean it's at the root of your domain.
Tried <link href="stylesheets/formtastic.css?1290524609" media="screen" rel="stylesheet" type="text/css" /> ?

Resources