1.父类div定义height
2.结尾处空div标签 clear:both
3.父类div上加上overflow:hidden
4.使用伪类方法
.div1{background:#000080;border:1px solid red;}
.div2{background:#800080;border:1px solid red;height:100px;margin-top:10px}
.left{float:left;width:20%;height:200px;background:#DDD}
.right{float:right;width:30%;height:80px;background:#DDD}
/*清除浮动代码 三种*/
/*.div1{overflow: hidden;}*/
/*.div1{height: 300px;}*/
/*.clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0}
.clearfloat{zoom:1}*/
<div class="div1 clearfloat">
<div class="left">Left</div>
<div class="right">Right</div>
</div>
<div class="div2">div2</div>
网友评论