我已经尝试了大约6种不同的方法,并没有能够得到这个工作。绝对中心格没有负边界
我试图居中“div.content”水平在页面上同时使用position:absolute;
此方法适用于所有的浏览器,但如果你缩小页面大小,滚动条出现在底部:
HTML:
<div class="wrapper">
<div class="header"></div>
<div class="footer"></div>
<div class="content">
<div class="content2">CENTER THIS DIV</div>
</div>
</div>
CSS:
div.header {
background:url('http://i.istockimg.com/file_thumbview_approve/11670843/2/stock-illustration-11670843-seamless-wallpaper-background-tile.jpg') top center repeat-x;
height:150px;
}
div.footer {
background:url('http://www.featurepics.com/FI/Thumb300/20081029/Blue-Tile-Background-947601.jpg') top left repeat-x;
height:150px;
}
div.content {
position:absolute;
top:20px;
left:50%;
height:250px;
width:300px;
}
div.content2 {
position:relative;
left:-50%;
background:white;
height:250px;
}
你为什么反对使用负边距?您正在使用的技术会导致水平滚动条出现,负边距会解决此问题。 – joshnh 2012-07-19 06:23:47
我的意思是:'left:-50%'。那是什么导致滚动条。如果你能解决这个负利润率,给我看代码! – supercoolville 2012-07-19 06:25:43