Is there a browser compatiblity issue with relative image paths in .css files?

只谈情不闲聊 提交于 2020-01-07 02:13:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!