The use of floating in CSS and the method of clearing floats

Source: Internet
Author: User

1. What happens when you use a float:

(1) make block elements appear on one line

(2) enable inline elements to support wide height

(3) when the width is not set wide, the content is Open.

(4) line breaks are not parsed (so the method of clearing gaps when using inline elements can use Float)

(5) the element adds a float that moves away from the document stream, moving in a specified direction until it touches the parent's border or another floating element stops (the document flow is where the realistic objects in the document occupy the Arrangement)

2. How to clear floating:

(1) Add a float to the parent element (in this case, the parent element margin:0 Auto; it cannot be centered)

(2) Add display to the parent element :inline-block; (the Previous method is not centered, only IE6,7 Center)

(3) add <div class= "clear" ></div>. clear{height:0px;font-size:0;clear:both under the floating element ; , but in IE6 , the block element has a minimum height, that is, when height<19px , the default is 19px , Workaround: font-size:0; or overflow:hidden;

(4) add <br clear= "all" under floating elements >

(5) Add {zoom:1} to the parent element

. clear{zoom:1}

. clear:after{content: "";d isplay:block;clear:both;}

(6) Adding Overflow:auto to the floating element parent ;

eg: CSS 's zoom property: theZoom property is The proprietary property of IE browser, Firefox and other browsers are not Supported. It can set or retrieve the scale of an object. In addition, it has other small functions, such as triggering IE 's haslayout property, Clearing the float, clearing the margin overlap and so on.

The use of floating in CSS and the method of clearing floats

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.