背景图像路径在CSS中不起作用 [英] background images path not working in CSS
问题描述
相对路径在CSS中不正确
Relative path not working in CSS while it's correct
{ width: 64px; background: url(../images/abc/xyz/bottom-navigation.jpg) no-repeat 0 0; }
Firebug出现此错误
文件夹路径
推荐答案
在CSS中,路径是相对于样式表的,因此请确保正确.根据您发布的代码,您的样式表必须位于一个文件夹中(例如 css
),并且该文件夹与 images
处于同一目录级别.
In CSS the path is relative to the stylesheet, so make sure you have that correct. Based on the code you posted, your stylesheet would need to be in a folder (e.g. css
) and that folder would be at the same directory level as images
.
另一种通常更好的选择是使用相对于您的域的路径.因此,如果images文件夹位于根目录中,则可以使用 url("/images/abc/xyz/bottom-navigation.jpg")
(请注意,在文件名中用引号引起来是一种很好的做法CSS).
The alternative and generally better option is to use a path that's relative to your domain. So if the images folder is in the root, you would do use url("/images/abc/xyz/bottom-navigation.jpg")
(note, it's good practice to put quotes around filenames in CSS).
另一种可能性是加载图像时出现某种问题.在Firebug中,您应该可以右键单击URL并打开图像.这样做并确保它加载并显示正确的路径.
The other possibility is that there is some kind of problem loading the image. In Firebug you should be able to right click the URL and open the image. Do this and make sure it loads and is showing the correct path.
这篇关于背景图像路径在CSS中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!