Three ways to surround floating elements

Source: Internet
Author: User

Method One: Apply Overflow:hidden to the parent element

In fact, the real purpose of the Overflow:hidden declaration is to prevent the inclusion element from being large by the oversize content. After applying Overflow:hidden, the containing element retains its set width, while the oversized child content is cut off by the container. In addition, Overflow:hidden has another effect, that is, it reliably forces the parent element to contain its floating child elements.

Method Two: Floating the parent element at the same time

The second way to induce the parent element to surround its floating child elements is to let the parent element float.

Method Three: Add non-floating purge elements

is simply to add a child element to the HTML tag and apply the clear property to it. Because there is no default style, no extra space is introduced, and the DIV element works well for this purpose.


Currently the most popular method of clearing floating, write a Clearfix class:

. clearfix:after{

Content: "";

Display:block;

height:0;

Visibility:hidden;

Clear:both;}

. clearfix{

* Zoom:1}

*zoom:1 is to start haslayout.

About Haslayout Introduction Click Http://baike.baidu.com/link?url=U_3B9202pp9xc357Ge9u7aS_ T1wmuyzzvj8ef4tyxqujtriz-4ggbft86csifnhssfpfqxllfrll0jjhpr7dek

1.display:block to make the generated elements appear as block-level elements

2.height:0 the content of the generated element destroys the height of the original layout.

3.visibility:hidden makes the generated content invisible and allows content that can be generated to be covered by clicks and interactions

4.content: ""; is to make the content part empty



Three ways to surround floating elements

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.