css - 背景图片不工作

标签 css background-image

我遇到了这个非常烦人的问题,过去几天我一直在努力解决这个问题。我什至在 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/

相关文章:

javascript - 用户点击链接问题时显示css背景图片

html - 如何用文字包裹图片(当前在背景中)

opencv - opencv如何在高斯混合中存储矩阵值?按什么顺序?

css - 如何根据CSS中哪个高度较大来获得两个相同高度的div

html - 对齐文本和线平行

html - 在html中获取水平规则的背景颜色

html - CSS 表格,不同尺寸

css - 小 div 内的大图像,没有裁剪或纵横比变化

javascript - 如何替换 css ('background-image' )

html - 照片网格 Internet Explorer 中不需要的底部边距