我遇到了这个非常烦人的问题,过去几天我一直在努力解决这个问题。我什至在 Stackoverflow 上阅读了所有可能的解决方案,但没有任何效果!
我的 HTML 中有这段代码:
<div id="picture">
<div class="picture-1"></div>
<div class="picture-2"></div>
<div class="picture-3"></div>
</div>
我的 CSS 中的这段代码:
#picture {
height: 250px;
border-top: 1px solid #ffefaf;
border-bottom: 2px solid #ffffff;
clear: both;
}
.picture-1 {
background: transparent url('images/view.png') left top no-repeat;
}
.picture-2 {
background: transparent url('images/plant.png') left top no-repeat;
}
.picture-3 {
background: transparent url('images/view.png') left top no-repeat;
}
图片在正确的文件夹中,名称正确,但它们不起作用。可能是什么问题?
最佳答案
您的图片 DIV
没有尺寸。它们不会像 IMG
标签那样自动将它们的大小设置为图像。您需要使用 width:
和 height:
在 CSS 中设置它。
关于css - 背景图片不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15028445/