我想在流体布局中设置容器div居中(id: articles_grid的内容必须居中):http://www.benskesblog.com/projects/frontend/project/index.htm
我试过很多方法,但没有一个奏效。(例如:margin: 0 auto;). 谁能告诉我怎么解决这个问题?谢谢
我相信改变是很简单的:
#articles_grid {
...
text-align: center; /*add this*/
}
#articles_grid li {
...
/* float:left; remove this */
display: inline-block; /*add this*/
}
你可以给display:inline-block
你想要的DIV
在中心&在parent DIV
中定义text-align:center。例如,你可以这样做:
.parent{
background:red;
text-align:center;
}
.center{
text-align:left;
display:inline-block;
*display:inline;/* IE7 */
*zoom:1;
background:yellow;
min-height:100px;
}
HTML: <div class="parent">
<div class="center">lorem ipsum</div>
</div>
检查下面的例子: