Six ways to clear floating, strongly recommended after clear floating

Source: Internet
Author: User

Six ways to clear floating

1. Add a floating float:left to the parent level

. box{width:300px;margin:0 auto;border:10px solid #000; float:left;}

. div{Width:200px;height:200px;background:red;float:left;}

<div class= "box" > <div class= "div" ></div> </div>

2. Add Display:inline-block to the parent level

. box{width:300px;margin:0 auto;border:10px solid #000; display:inline-block;}

. div{Width:200px;height:200px;background:red;float:left;}

<div class= "box" > <div class= "div" ></div> </div>

3. Under floating elements Add <div class= "clear" ></div>. clear{Height:0px;font-size:0;clear:both;}

<div class= "box" > <div class= "div" ></div> <div class= "clear" ></div> </div>

. box{width:300px;margin:0 auto;border:10px solid #000;}

. div{Width:200px;height:200px;background:red;float:left;}

. clear{Height:0px;font-size:0;clear:both;}

4. Add <br clear= "All" under floating elements/>

<div class= "box" > <div class= "div" ></div> <br clear= "All"/> </div>

5. Parent of floating element (after clear float) recommended

{zoom:1;} * * Floating element under ie6,7, Haslayout calculates the width of the element based on the size of the content of the element or the size of the parent's parent

: after{content: ""; Display:block;clear:both;} Other browsers clear floating

. box{margin:0 auto;border:10px solid #000;}

. div{Width:200px;height:200px;background:red;float:left;}

. Clear{zoom:1;}

. Clear:after{content: ""; Display:block;clear:both;}

<div class= "box clear" > <div class= "div" ></div> </div>

6. Add Overflow:auto to the parent level; Zoom:1 (IE6)

. box{width:300px;height:300px;border:1px solid #000; overflow:auto;}

. div1{Width:260px;height:400px;background:red;float:left;}

. box{width:300px;height:300px;border:1px solid #000; overflow:hidden; zoom:1;} /*overflow:auto: It's OK.

. div1{Width:260px;height:400px;background:red;float:left;}

Six ways to clear floating, strongly recommended after clear floating

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.