问题
I have .css
files with relative references to images like this:
BODY
{
BACKGROUND: url(bg.gif);
}
where the bg.gif
file is located in the same folder as the .css
file. This seems to work fine in my testing but I notice some errors in my logs that indicate that some browsers are trying to find bg.gif
in the same folder as the .html
page that refers to the .css
file, not the folder where the .css
file is.
Here's an example of one such HTTP_USER_AGENT
: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7
I have tried searching this online and find conflicting information.
回答1:
As far as my knowledge goes, none of the modern browsers have any such problems. Relative paths are very well supported.
回答2:
I've never heard of anything having this problem...I'd suggest tying to link them with the full relative path, or perhaps placing them into a images folder and linking through that (sort of like a reset, 2nd chance).
回答3:
that can be something to do with base url for the page. You might want to specify it so the browser knows how to access files.
Add base element to head (as below) section and let me know
<head>
<base href="http://mysite.com/images/" target="_blank" />
</head>
Hope it helps.
来源:https://stackoverflow.com/questions/9134455/is-there-a-browser-compatiblity-issue-with-relative-image-paths-in-css-files