css--Clear Float

Source: Internet
Author: User

Floating clear environment: when we have a large box, there are a few small boxes nested inside, because the contents of the small box are changed. It is possible that its length will continue to grow until it exceeds the length of the large box. Large box at this point, defining a specific length is somewhat meaningless, since the final length is based on the length of the Inner small box. The Inner small box is set to float because of the layout. So this leads to a phenomenon where the box underneath the big box will come up on top, such as:

Ways to eliminate floats:

1, Clear:left | Right | Both (do not set the height of the parent element when using this.) )

2. Use Overflow:hidden for the parent element (do not set the parent element's height when this is used). )

3, pseudo-element clear floating (this use when the parent element is not set high.) )

<!     DOCTYPE html>. Header,. Main,. footer {width:500px;            }. Header,. footer {height:100px; Background: #000;            }. Main {background: #eee; margin:10px0; /*Overflow:hidden;*/}. Content {width:300px;            height:300px;            Background:orange; float: Left;            }. sidebar {width:190px;            height:300px;            Background:green; float: Right; }. Clearfix:after {content:".";            Display:block; Height:0; Line-height:0;            Visibility:hidden;        Clear:both; }        /*compatible with IE browser*/. clearfix {zoom:1; }    </style>

Effect:

css--Clear 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.