3个div水平居中

来源:互联网 发布:ie8 f12 没有网络捕获 编辑:程序博客网 时间:2024/05/22 02:09
<div style=" margin:auto; width:346px; height:102px; border:solid 1px #000000;">
<div style=" width:100px; height:100px; border:solid 1px blue; float:left; margin-left:10px;"></div>
<div style=" width:100px; height:100px; border:solid 1px red; float:left; margin-left:10px;"></div>
<div style=" width:100px; height:100px; border:solid 1px yellow; float:left; margin-left:10px;"></div>
</div>

div要横向排列就要用float,居中要用margin-left:auto;margin-right:auto,但是有float,这个margin-left:auto;margin-right:auto;就会出问题,所以就要在外围定义一个容器,在外围设置margin-left:auto;margin-right:auto居中
0 0