Method one adds (generate BFC block-level formatting context) {overflow: hidden; } Add an empty div {clear:both; height:0; overflow:hidden; } add a class name to the floating element's parent. Clean :after{content:'.'; display:block; clear:both; height:0; overflow:hidden; visibility:hidden; } IE6 and below:.clean{zoom:1; }Copy the code

Causes:

If the parent element contains only floating elements and the parent element has no height or width set, its height will be scaled to zero. This is because floating elements fall out of the document flow and have no content in the parent block surrounding them, so they “collapse.”