HTML structure
1 <Divclass= "Wrap">2 <Divclass= "Div1">1</Div>3 <Divclass= "Div2">2</Div>4 <Divclass= "Div3">3</Div>5 </Div>
CSS Styles
1 . Wrap{margin:10px;Padding20px;border:5px Solid Gray;Background-color:#fff;}2 . Div1{float: Left;Height:100px;width:100px;Background-color:Lightgray;}3 . Div2{float: Left;Height:100px;width:100px;Background-color:Skyblue;}4 . Div3{float: Left;Height:100px;width:100px;Background-color:Red;}
You can see that the height of the outer wrap Div is not propped up because the inner element floats out of the text stream and we need to clear the float. Here are three common ways to clear floats.
1. Add an empty element after the last inner element, using the Clear:both
1 <Divclass= "Wrap">2 <Divclass= "Div1">1</Div>3 <Divclass= "Div2">2</Div>4 <Divclass= "Div3">3</Div>5 <Divclass= "Clear"></Div>6 </Div>
1 . Clear {Clear:both;}
2. Add Overflow:hidden or Auto properties to the outer element.
1 . Wrap {2 overflow:auto; 3 zoom:1; /* Handling compatibility issues */4 }
3. Add a pseudo-element to the outer element after, using after simulation to create the element div.clear. (recommended, can be used as a public style)
1 <Divclass= "Wrap Clearfix">2 <Divclass= "Div1">1</Div>3 <Divclass= "Div2">2</Div>4 <Divclass= "Div3">3</Div>5 </Div>
1 . Clearfix{2 Zoom:1;/*dealing with IE compatibility issues*/3}4 . Clearfix:after{5 Display:Block;6 Visibility:Hidden;7 content:'. ';8 Clear:both;9 Height:0;Ten Overflow:Hidden; One}
CSS Clear Float method