Advantages of clear in CSS

Source: Internet
Author: User
In the DIV + CSS design webpage, you often need to set multiple divs to be arranged in parallel, usually Using Float: Left or float: Right, but the problem arises, the total width of multiple divs in the current side is less than 100%. The DIV below is likely to be raised up, and it is in the same row as the DIV in the previous row. This is not the expected result. The clear attribute can solve this problem. The following describes the help:

CSS clear attributes

Image and text elements that appear in another element are called floating elements. The clear property sets the sides of an element where other floating elements are not allowed.
When image and text elements appear in other elements, they (images and text) can be called floating elements ). The clear attribute can be used to prevent other floating elements from appearing on the edge of an element.

Note:This property does not always work as expected if it is used along with the "float" property.
Note:When this attribute is used with the "float" attribute, the results may be unsatisfactory.

Inherited:No
Inheritance:None

Available Value

Value Description
Left No floating elements allowed on the left side
Float elements on the left of an element are not allowed.
Right No floating elements allowed on the right side
Float elements are not allowed on the right of an element.
Both No floating elements allowed on either the left or the right side
No floating element is allowed on both sides of the element.
None Allows floating elements on both sides
Allow floating elements on both sides

 

Example

<Style type = "text/CSS">

. Lefttext {
Margin: 3px;
Float: left;
Height: 180px;
Width: 170px;
Border: 1px solid # b1d1ce;
Background-color: # f3f3f3;
}

. Foottext {
Height: 180px;
}

. Clear
{
Clear: both;
}
</Style>

<Div class = "lefttext"> Block 1 </div>
<Div class = "lefttext"> Block 2 </div>
<Div class = "clear"> </div>
<Div class = "foottext"> block 3 </div>

CodeNote:

If the layer is not clear, block 3 is tied to block 2 in the same row.
After the clear layer is added, the effects of the above floating Div will be cleared so that it will not affect the layout of the following Div

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.