清除浮动

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}*/
Left
Right
div2

你可能感兴趣的:(清除浮动)