Reputation: 21
On domain1.com I have a simple html page:
<h1 class="hello-world">Hello World!</h1>
This page references an external CSS file which is hosted over on domain2.com. All of the images within that CSS file are referenced using relative paths. E.g:
h1.hello-world {
background-image:url(/images/cute-kitten.gif);
}
When I load the page on domain1 does the browser try to reference the image 'domain1.com/images/cute-kitten.gif' or 'domain2.com/images/cute-kitten.gif'?
And will the result be the same in all (current) browsers?
Upvotes: 1
Views: 2250
Reputation: 95364
According to the CSS Level 2 specification document, relative URIs are always resolved using the URI of the stylesheet which includes the path.
In order to create modular style sheets that are not dependent on the absolute location of a resource, authors may use relative URIs. [...] For CSS style sheets, the base URI is that of the style sheet, not that of the source document.
Therefore, it will always be resolved to http://domain2.com/images/cute-kitten.gif
on all browsers.
Upvotes: 2