Welcome to MSDN Blogs Sign in | Join | Help
Hmm - how do you reference a remote .css inline?

Well, the short answer is (i think): you can't.  Early on in my search for the answer, I ran across this article on w3schools stating that you can either:

  • create your stylesheet explicitly in the <head> element of the page (<head><style>blar blar blar...)
  • reference a common stylesheet in the <head> element of the page (<head><link href="style.css" blar blar blar...)
  • inline the style qualities on the elements in question (<p style="background:red;">this isn't so hot...</p>)

Well, I thought that I'd fiddle around anyways to just see what I could find and got all excited when I saw the 'src' sub attribute of the style property on a div tag:

<div style="src:url(StyleSheet.css)">

Unfortunately that is only for the url of the font to download.  :(  I was really hoping to avoid inline for the scenario I need to implement but I might just have to.  Any help would be appreciated.

Posted: Wednesday, April 04, 2007 2:25 PM by mr.m
Filed under: ,

Comments

Jessica said:

I'm no expert but I'd also go with "can't be done", and if you could it would have to be something awfully hacky as I haven't ever seen it done or discussed in all the material I've been studying lately.

The absolutely nicest way to use CSS is by linking to the files in head (option 2), that way you can have separate style sheets for areas, though you need to consider the order you include them and any overlaps which may cause conflicts. Depending on how the (X)HTML is generated you might want to conditionally include a css file for the section you're having trouble with on relevant pages, if you can know at the start whether it will be needed or not. If it was a ridiculously huge css file you might be apprehensive about including it when it might not be necessary, but worst case it's only included for pages that might requiure it and not throughout an entire site (where in most cases it's definately not needed).

Sorry this doesn't help much, again, I'm only relatively new to this myself but I have been studying ways to apply CSS quite a bit recently and as I said above, have never seen or heard of doing this.

# April 4, 2007 8:56 PM

mr.m said:

Huh - well, I found a non-XHTML compliant way to solve the problem (you can drop a <link> element within a <div> element).  Actually, my boss (senor seven) replied to this post in an email wanting to know what I was about and mentioned this tactic.  Still not ideal, but if xhtml compliance isn't a biggie, it's better than inline styles...

# April 5, 2007 2:32 PM
New Comments to this post are disabled
Page view tracker