我很难通过 css 中的 background-image 属性添加图片 我的文件结构如下所示:
www
styles
stylesheet.css
images
background.jpg
我试过:
background-image: url("/images/background.jpg");
background-image: url("images/background.jpg");
background-image: url("background.jpg");
background-image: url("../images/background.jpg");
background-image: url("/../images/background.jpg");
background-image: url("../../images/background.jpg");
我还尝试了所有这些不带引号的选项。我复制粘贴了图像的名称,我的文件夹如我所说:主文件夹,其中有样式文件夹(里面是 stylesheet.css)和图像文件夹(里面是 background.jpg)。该图像未在 chrome 或 firefox 中加载。我应该使用什么路径声明来使图像显示?
最佳答案
www
index.html
styles
stylesheet.css
images
background.jpg
那个目录,在 index.html/index.php 里面(你想显示的地方)
<link href="styles/stylesheet.css" rel="stylesheet" type="text/css" />
记住href链接 然后在 stylesheet.css
background-image: url("../images/background.jpg");
关于CSS 背景图像路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34099430/