Re-discussion on clearing floating-space Div method

Source: Internet
Author: User
Tags empty visibility

The use of floating CSS will cause confusion in the layout, and usually the way to clear the float is to use an empty Div with the following style:

<div class= "Clear" ></div>
Clear{clear:both;}

The more excellent CSS code is:

. Clear:after{content: "."; Display:block;height:0;clear:both;visibility:hidden}
. Clear{zoom:1;}

This method is now widely used, Taobao, Word-of-mouth, are the use of this. After the pseudo class: After and for the IE6 of the independent CSS Hack to achieve, fully compatible with the mainstream browser.

Of course, it's not necessary to append "." After the element through CSS, because it needs to be visibility to hide it. By optimizing, the code is as follows:

. Clear:after{content: "020";d Isplay:block;height:0;clear:both;
Clear{zoom:1;}

Where 020 refers to adding spaces after the container, thus avoiding the use of visibility to hide visibility.

In addition, the method of using empty div is not recommended. It would be a bit abrupt to insert a container without semantics in well-formed HTML simply to clear the float.



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.