The Clear property of CSS

Source: Internet
Author: User

The following references are from W3school

The clear property defines the side on which the element is not allowed to appear floating elements. In CSS1 and CSS2, this is achieved by automatically increasing the upper margin for the purge element (that is, the element that has the clear attribute set). In CSS2.1, the clearance space is increased above the outer margin of the element, and the margin itself does not change. Either way, the end result is the same, and if the declaration is left or right cleared, the element's Sisu border boundary is just below the margin of the floating element on that edge.

value Description
Left Floating elements are not allowed on the left side.
Right Floating elements are not allowed on the right.
Both Floating elements are not allowed on the left or right sides.
None The default value. Allows floating elements to appear on both sides.
Inherit Specifies that the value of the clear property should be inherited from the parent element.

Situation one: DIV1 (gray) left floating DIV2 (blue) right floating

float: left; width:200px; height:200px; background-float: right; width:200px; height:200px; Background-color: #0088cc; }

DIV2 when using Clear:left, clear the float to do the effect

DIV1 clear:right or Clear:both, can not clear right floating.

Case two: DIV1 right floating DIV2 right floating

float: right; width:200px;height:200px;background-float: right; Width:200px;height:200px;background-color: #0088cc;}

DIV2 Clear:right; Clear the floating on the right

DIV1 clear:right or Clear:both, can not clear the right floating

Case three: DIV1 right floating DIV2 left floating

float: right; width:200px;height:200px;background-float:left;  }

DIV2 Clear:right, clear the right float

DIV1 Clear:left or Clear:both, can not clear left floating

Situation four: DIV1 left floating DIV2 left floating

float: left; width:200px;height:200px;background-float: left; Width:200px;height:200px;background-color: #0088cc; }

When DIV1 with Clear:right, can not clear floating, when DIV2 with Clear:left, clear left floating

Conclusion:

Clear is based on the top boundary of the purge occurs. There are no other labels on the top of this example DIV1, and no DIV2 floats can be cleared in any direction. The next element, DIV2, can determine whether the previous element has floated, and the following label is moved below because of the clear float.

The Clear property of CSS

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.