The clear property of CSS clears floating usage in detail

Source: Internet
Author: User
What is css clear float?

The popular view on the Internet is that in non-IE browsers (such as Firefox), when the height of the container is auto, and the contents of the container are floating (float is left or right), in which case the height of the container cannot be automatically stretched to fit the height of the content. A phenomenon that causes content to overflow outside the container and affect (or even destroy) the layout. This phenomenon is called floating overflow, in order to prevent the occurrence of this phenomenon of CSS processing, called CSS to clear the float.

Use the clear style to clear
Examples:

. clear-float {Clear:both;}

The clear property is provided by CSS 1 to clear the floating style, the element with the clear property set, and its top border position is rendered against the Margin-bottom boundary position of the floating element, ignoring its margin-top settings. This way, when the parent container height is not set (the value is auto), the actual height of the container is included as a floating element because the defined cleanup floating style element is positioned below the floating element.

Instance
Added P4 in the code and set the width to 300px, gray background color, the code is as follows

HTML code:

<p class= "P4" >    P4   </p>

CSS code:

. p4 {       width:300px;       height:300px;       Background-color:darkgray;   }

The effect is as follows:

1. By the red line is P4, we will find a problem, is that the P4 is still from the top left corner of the arrangement, but the text is not in the upper left corner of the position, this is floating will bring problems.
2. If we want to implement the effect that P4 is affixed to the right side of P2 and P3, we also need to set the Float:left property description for the P4
But we do not want this effect, but want to let P4 in the following rearrange, and not follow P1, p2, p3 they float, this time, we need to clear floating

. p4 {       width:300px;       height:300px;       Background-color:darkgray;       Clear:both;   }

Just add clear:both; properties, you can clear the float.

The effect is as follows:

After clearing the float, the P4 can be arranged from below, and will not participate in the above several P floats. This is known as the clear float.

Related Article

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.