Use after pseudo class to clear floating

Source: Internet
Author: User
Previously cleared floats are always added after the element that you want to clear floating

<div style= "Clear:both;" ></div>

or written in the BR tag to solve, but this will increase the non-semantic tags, the following pseudo-class implementation, compatible with a variety of browsers

. clearfix:after{    content: "";    Display:block;    height:0;    Clear:both;    Visibility:hidden;}

is compatible with IE6,IE7 because the IE6,IE7 cannot be used after pseudo class. Add the following code

. clearfix{zoom:1}

In general, if there is a float (float) inside the parent layer may cause the parent layer to have a height of 0, plus clearfix.

Html:

<p class= "Parent Clearfix" >     <p class= "left" >left</p>     <p class= "right" >right</p > </p>

Css:

. clearfix{zoom:1}    . clearfix:after{    content: "";    Display:block;    height:0;    Clear:both;    Visibility:hidden;}. parent{    background-color:red;    width:120px;}. left{    Float:left;    Background-color:pink;    height:60px;}. right{    float:right;    Background-color: #abcdef;}

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.