标签:
1.在浮动元素尾部加空div
<div id="wrap" class="warp"> <div id="one" class="clo" ></div> <div id="two" class="clo"></div> <div id="three" class="clo"></div> <div id="four" class="clo"></div> <div style="clear:both"></div> </div>
.warp{ width:1260px; margin:auto; border:1px solid red; } clo{ width:80%; height:100px; float:left; background-color:#e34cf1; border:5px solid #fff; }
2.父元素设置overflow:hidden;
<div id="wrap2" class="warp">
<div id="one" class="clo" ></div>
<div id="two" class="clo"></div>
<div id="three" class="clo"></div>
<div id="four" class="clo"></div>
</div>
#wrap2{ border:2px solid green; overflow:hidden; }
3.为父元素添加伪类
<div id="wrap3" class="warp">
<div id="one" class="clo" ></div>
<div id="two" class="clo"></div>
<div id="three" class="clo"></div>
<div id="four" class="clo"></div>
</div>
#wrap3:after{ content:" "; display:block; height:0px; clear:both; }
标签:
原文地址:http://www.cnblogs.com/pangys/p/5732349.html