61,115
社区成员
发帖
与我相关
我的任务
分享
<div style=" width:100%; height:200px; border:1px solid red; text-align:center; margin:0px auto;">
<div style=" width:150px;; height:120px; border:1px solid yellow; margin:10px 10px 0px 0px; float:left; "></div>
<div style=" width:150px; height:120px; border:1px solid red; float:left; margin:10px 10px 0px 0px; "></div>
</div>
<div style=" width:100%; height:200px; border:1px solid red; margin:0px auto;">
<div style=" width:20%;; height:120px; border:1px solid ; display:inline-block; margin:10px auto 0px 30%;"></div>
<div style=" width:20%; height:120px; border:1px solid red; display:inline-block; margin:10px auto 0px auto;"></div>
</div>
外层div是百分数,内层如果px设置长度,那么想要居中则要需要计算margin的宽度。把内层的div宽度也设置成百分比可以解决。
<div style=" width:100%; height:200px; border:1px solid red;margin:0px auto;">
<div style="width:345px; margin:0px auto;">
<div style=" width:150px; height:120px; border:1px solid yellow; margin:10px 10px 0px 0px; float:left; "></div>
<div style=" width:150px; height:120px; border:1px solid red; float:left; margin:10px 10px 0px 0px; "></div>
</div>
</div>