CSS floating cleanup, do not use Clear:both tags _ experience Exchange

Source: Internet
Author: User
For example:

Some Content

Now preview this code and we'll find the outermost parent element float container, and it's not displayed. This is because the child element is floating and detached from the document stream, resulting in a parent element having a height of zero.
If you modify the code to:

Some Content


Notice that there is a bit more code to clean up the float. This is a good CSS code habit, but this method adds useless elements. Here's a better way to change the HTML code to:

Some Content

Defines a CSS class for "floating cleanup" control:
Copy CodeThe code is as follows:
. Clearfix:after {} {
Content: ".";
Clear:both;
height:0;
Visibility:hidden;
Display:block;
}/* This is the processing of Firefox, because Firefox supports the generation of elements, and all versions of IE do not support the generation of elements */
. Clearfix {} {
Display:inline-block;
}/* This is the processing of IE browser on MAC */
/**//* hides from Ie-mac \*/
* HTML. Clearfix {}{height:1%;}/* This is for the IE browser on Win * *
. clearfix {}{display:block;}/* This is a change made to Display:inline-block; reset to block element */
/**//* End Hide from Ie-mac */

At this point, previewing the above code (by deleting this comment) will find that even if the child element floats, the parent element, float container, will still surround it, making it highly adaptive.
  • 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.