Css 页面容器';t高度

Css 页面容器';t高度,css,html,height,Css,Html,Height,我有这个网站,我已经(非常恢复): 测试在这里:将主体的宽度设置为1024并将其居中,这将允许您浮动div <body style="width: 1024px; margin: 0px auto; text-align: center;"> }一个简单的解决方案是将溢出:auto添加到您的容器(#contendor): 活生生的例子:您有很多未清除的浮动。我将添加一个伪元素,在contendor之后清除: #contenedor:after { content:"\002

我有这个网站,我已经(非常恢复):


测试在这里:

将主体的宽度设置为1024并将其居中,这将允许您浮动div

<body style="width: 1024px; margin: 0px auto; text-align: center;">

}一个简单的解决方案是将
溢出:auto
添加到您的容器(
#contendor
):


活生生的例子:

您有很多未清除的浮动。我将添加一个伪元素,在contendor之后清除:

#contenedor:after {
    content:"\0020";
    display:block;
    height:0px;
    overflow:hidden;
    clear:both;
}

就个人而言,比起@tw16的“溢出”技巧,我更喜欢这一点,因为如果你想在contendor之外定位一些东西,你仍然可以。

这是一个不错的解决方案,但由于它在IE7中不起作用,当然,一行中可以完成的事情有很多行。但如果你担心CSS的线条,这就像优步优化一样。@Toni Michel Caubet伪元素在IE8+中工作。如果您需要IE7支持,则不应使用此方法。幸运的是,IE7只占全球浏览器市场份额的2.65%(而IE8+只占39%),所以我个人选择专门使用它。这取决于你的观众对你的发展。
<body style="width: 1024px; margin: 0px auto; text-align: center;">
#contenedor {
 display: block;
 background:  white;
 width: 1024px;
 padding: 44px 2px 2px;
 position: relative; /* is relative so the margin auto works */
 margin: auto;
 float: left;
#contenedor{
    display: block;
    background:  white;
    width: 1024px;
    padding: 44px 2px 2px;
    position: relative; /* is relative so the margin auto works */
    margin: auto;
    overflow: auto; /* ADD THIS LINE */
}
#contenedor:after {
    content:"\0020";
    display:block;
    height:0px;
    overflow:hidden;
    clear:both;
}