【发布时间】:2015-05-04 22:13:52
【问题描述】:
我正在尝试设置一系列带有背景图像的 div,每个 div 都有自己的固定高度,并拉伸以填充宽度,即使顶部/底部有溢出被剪裁。我只是不想要边缘的空白。
目前,我有:http://jsfiddle.net/ndKWN/
CSS
#main-container {
float:left;
width:100%;
margin:0;
padding:0;
text-align: center;
}
.chapter{
position: relative;
height: 1400px;
z-index: 1;
}
#chapter1{
background: url(http://omset.files.wordpress.com/2010/06/homer-simpson-1-264a0.jpg) 50% 0 no-repeat fixed;
height:1200px;
}
#chapter2{
background: url(http://download.ultradownloads.com.br/wallpaper/94781_Papel-de-Parede-Homer-Simpson--94781_1680x1050.jpg) 50% 0 no-repeat fixed;
height:1200px;
}
【问题讨论】:
-
“边缘空白” ...您是指主体的“全局”填充吗?那就试试:
body { padding: 0px; margin: 0px; }? -
body padding 和 margin 都是 0;当您在浏览器上查看宽度超过图像宽度的页面时,就会出现问题。背景图像未水平填充。