<head> <meta charset="UTF-8"> <title></title> <style> #parent { border: 1px solid blueviolet; } #childone { float: left; width: 200px; height: 400px; background-color: #AFEEEE; } #childtwo { float: left; width: 200px; height: 200px; background-color: #FFB6C1; } #parent::after { content: ""; display: block; /*height: 0;*/ clear: both; /*visibility: hidden;*/ } </style> </head> <body> <div id="parent"> <div id="childone"></div> <div id="childtwo"></div> </div> </body>
after伪元素必须配合content使用
clear:both只在块级元素上生效