I have a div with floating children.
I know that I can stretch the height in two ways:
.container { border: 2px solid #ccc; margin-bottom: 250px; } .container-2::after { content: ''; display: block; height: 0; font-size: 0; clear: both; } .container-3 { overflow: hidden; } .item { float: left; width: 200px; height: 50px; background: red; margin: 10px; }
<div class="container container-1"> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div> <div class="container container-2"> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div> <div class="container container-3"> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div>
But I think that they have different principles: the clear:both :: after element remains from the brothers with a floating point and causes the parent div to stretch the height; the overflow:hidden style causes the div to have BFC, and according to the standard , BFC will stretch its height to include its floating point children.
Advantages and disadvantages are not important, but how they work.
I'm right, they are different, but have the same result?
yanni4night
source share