CSS---floating problem

Source: Internet
Author: User

Floating: When an element contains a floating element, the element is automatically shrunk rather than being stretched by a floating element;

Floating instances:

When not floating:


Effect in Browser:


After adding a float:


In the browser:


You can see that the parent element with the class name wrap is highly collapsed and becomes a line after adding a float.

The methods for clearing floats are:

1, after the floating element plus a class name clear blank tag, and in the CSS style Liqingfeng except floating. (added a meaningless empty tag)


2, to the parent element wrap defined height (but is not applicable when the height is unknown)


3, add style Overflow:hidden/scroll/auto to the parent element. (May hide useful things when using hidden)


4. Add Clearfix to the parent element class name and add it to the style.

. Clearfix:before,.clearfix:after{display:table;content: "";}
. Clearfix:after{clear:both;}

. clearfix{*zoom:1}


These four methods can clear the float (all can achieve the effect without floating, but have their own shortcomings and advantages)

Effect:

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.