HTML:不显示背景图像
答
您需要添加高度和宽度属性才能使用背景图像。
#counter1 {
background-image: url(http://i.imgur.com/7NMEPIo.jpg);
width:600px;height:340px;
}
here is a fiddle with a working version
你应该重新考虑使用其他字体颜色;-)
答
元素与id=counter1
没有内容*(float
移动元素了公文流转),div的高度为0,它的原因为什么你看不到背景图像。
#counter1 {overflow: hidden}
http://jsfiddle.net/huspk2j1/9/
*) 检查这个小提琴http://jsfiddle.net/huspk2j1/11/,我已经添加到border: 1px solid blue
向#counter1
告诉你它是空的。
答
基本上,因为浮动计数器不会导致它的父级正确计算高度。您可以使用overflow: hidden
属性修复此问题。
#counter1 {
background-image:url(http://i.imgur.com/7NMEPIo.jpg);
overflow: hidden;
}
答
添加
#counter1:after {
clear: both;
content: "";
display: table;
}
到你的CSS。
答
为了解决这个问题,你可以用clear: both
在你的容器的末尾简单地添加元素。
在此处查看更新代码:http://jsfiddle.net/aksruLLh。
+0
你需要更多的标记。我认为'overflow'方法更清洁。 – Hless 2014-10-27 13:50:54
你好,谢谢你的回答,只是一个很小的问题,如果我可以。我想让我的照片在整个网站上都保持100%的宽度,并且不再重复。然而,每次我这样做,它只会覆盖25%的网站,你认为你知道答案吗? [见这里](http://jsfiddle.net/huspk2j1/14/) – arrey 2014-10-28 14:12:27
也许这可以帮助你: http://stackoverflow.com/questions/235855/how-do-i-stretch-a-background- image-to-cover-the-entire-html- – 2014-10-28 14:14:36
谢谢,它的确如此。 – arrey 2014-10-28 14:21:46