这是 html,例如:
<td class=topleft width=10 height=10></td>
这是 CSS:
td.topleft{
border:0px;
width: 100px;
background-image: url(images/topleft.png);
background-repeat:no-repeat;
}
目录结构(从我桌面上名为 site 的文件夹开始)
网站.html
样式.css
/images/topleft.png
注意:否则样式将从 css 文件填充。
我试过文件的绝对路径:
background-image:url(file:///C:/Users/user/Desktop/site/images/topleft.png);
如果我直接将该 url 放入浏览器,则可以访问并显示图像。
最佳答案
尝试使用这个 HTML:
<td class="topleft"> </td> <!-- TD not empty, inserting blank space -->
和这个 CSS:
td.topleft
{
border: 0px;
width: 100px;
height: 100px;
background-image: url(images/topleft.png);
background-repeat: no-repeat;
}
验证图像文件名是否为小写,即使在扩展名中也是如此。确认 images
文件夹也是小写的。有用吗?
关于HTML & CSS - 背景图像 :url not showing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16641623/