css清除浮动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box { border: 1px solid red; /* overflow: hidden; 第二种方式清除浮动 */ } /* 第三种方式清除浮动:伪元素清除浮动 */ .clearfix:after { content: ''; display: block; height: 0; clear: both; visibility: hidden; } /* 兼容ie6、7版本 */ .clearfix { *zoom: 1; } .one { width: 200px; height: 200px; background-color: pink; float: left; } .two { width: 200px; height: 200px; background-color: pink; float: left; margin: 0 10px; } .three { width: 200px; height: 200px; background-color: pink; float: left; } </style> </head> <body> <div class="box clearfix"> <div class="one">1</div> <div class="two">2</div> <div class="three">3</div> <!-- 第一种方式清除浮动 --> <!-- <div style="clear: both;"></div> --> </div> </body> </html>