清除浮动父级塌陷
<head> <meta charset="UTF-8"> <meta name="author" content="xianwei"> <title>box模型演示</title> <style> div.container { width: 400px; border: 20px solid; } div.box{ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; width: 50%; border: 10px solid red; float: left; color: blue; background: chartreuse; } div.clearfix::after { content: ""; display: block; clear: both; } </style> </head> <body> <div class="container clearfix"> <div class="box"> 这个div占据左边 </div> <div class="box"> 这个div占据右边 </div> </div> </body>