Summary of methods for clearing floating float

Source: Internet
Author: User
Discard those useless methods, only remember the most practical one way!

Add a class attribute to the parent element to clear the float: clearfix!!!

The styles are as follows:

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

}

In order to be compatible with IE6,IE7 (now the project is almost completely out of consideration)

. clearfix{

Zoom:1

}

Clear float is so simple, can be used as a public style common.css, each page can be called directly!

A simple example application:

<div class= "Clearfix" >

<div style= "Float:left" >

Sth

</div>

<div style= "Float:right" >

Sth

</div>

</div>

Why to clear float:

1. The previous writing will find that the page is written with the confusion, and there is overlap? Is the trouble of floating!

2. The child element under the parent element, float, may cause the parent height value to be 0, so after using float, immediately add clearfix to the parent, eliminating all the weird problems that float brings!

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.