CSS Universal Purge principle

Source: Internet
Author: User

If there is a way to clear the float now, but not in the document more than one unused empty tag, then the effect is the best!
Introduced: after pseudo element selector, you can add the last child element to the contents of the specified element

. container:after{

}

How do I write content? ---->content property, write content

So

. container:after{
Content: ".";
}

The content that was just written is the inline element, and the clean float must be a block Object!!

So,--->display, convert inline elements to block-level elements

So

. container:after{
Content: ".";
Display:block;
}

Of course, you also need to add the Clear:both attribute to clear the float, so

. container:after{
Content: ".";
Display:block;
Clear:both;
}

Problem, the added content can also be rendered in the page effect, so the height is cleared to zero

. container:after{
Content: ".";
Display:block;
Clear:both;
height:0;
}

Although the height is clear to zero, but the text is still displayed, in fact, now the text has exceeded the size of the container, now only need to hide the overflow of the part can be

So
. container:after{
Content: ".";
Display:block;
Clear:both;
height:0;
Overflow:hidden
}

This enables the ability to clean up floats, but not a single empty tag in the document

CSS Universal Purge principle

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.