我有这个网站(恢复了):

<body>
   <div id="container">
      <!-- all html in here -->
   </div>
</body>


问题是我需要页面居中(所以我不能使用float),

主体有background:#ddd,容器有background:#fff

问题是除非我以px设置容器的min-height或height(或者如果我设置float但不兼容),否则白色背景是不可见的,

#容器标记为:

#contenedor{
    display: block;
    background:  white;
    width: 1024px;
    padding: 44px 2px 2px;
    position: relative; /* is relative so the margin auto works */
    margin: auto;

}


测试在这里:http://jsfiddle.net/bfzWN/

最佳答案

一个简单的解决方案是将overflow:auto添加到您的容器(#contenedor)中:

#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 */
}


实时示例:http://jsfiddle.net/bfzWN/1/

10-07 19:07
查看更多