0

这应该是一个将容器放在页面中心的非常简单的过程。

<style type="text/css">
    body{
       margin: 0;
       padding: 0;
    }
    #container{
       width:960px;
       float:left;
       margin:0 auto;
    }
</style>
...
<div id="container">
   Content
</div>

谁能告诉我为什么container不居中?

谢谢

4

2 回答 2

6

margin:0 auto;为左右提供自动边距,这将使其居中。

如果它没有居中,那将是因为float:left;

于 2012-04-05T15:19:28.513 回答
2

您的意思是“没有出现”吗?

设置和删除。text-align:center;_bodyfloat:left;#container

于 2012-04-05T15:19:26.300 回答