When it comes to CSS the following rule applies:
Partial URLs are interpreted relative to the source of the style sheet,
not relative to the document.
But here’s my problem :
I have different websites that use the same CSS file. While they use the same layout, the actual images the CSS references are different for each one of them.
Exemple:
#header {
width: 960px;
height: 200px;
background: url(/images/header.png);
}
Each domain has its own “images” folder and its own “header.png” that I would like the CSS to reference. Currently it behaves as it’s supposed to and tries to find the png file on the domain where the CSS is hosted. What I want is for it to get the png file from the domain where the CSS file was called.
I use “link” for the stylesheets because “@import” breaks progressive rendering in IE.
Any suggestion or workarounds?
You’re going to have to have separate URLs for each domain referenced. So
www.example1.comreferences its stylesheet as/style/sheet.cssand thus grabs it fromhttp://www.example1.com/style/sheet.csswhilstwww.example2.comgets it fromhttp://www.example2.com/style/sheet.css.However just because they look different from the client end that doesn’t mean they have to be different files on the server side (with all the maintenance that would imply). You could just point an
Aliason each domain to the real, shared CSS file.The only other workaround I can think of would be to split out the URL-referencing rules like
background-imageand put them in a domain-specific stylesheet or an internal stylesheet.