Div+css's clear float

Source: Internet
Author: User

1. The parent setting is appropriate for the CSS height
For the parent setting to fit the height style clear float, here to ". Divcss5" set a certain height, the general setting height needs to be able to determine the content height to set. Here we know that the content height is 100px+ the upper and lower border is 2px, so that the specific parent height is 102px

2, Clear:both Clear floating

To unify the style, we create a new style selector CSS named ". Clear", and the corresponding selector style is "Clear:both", then we add this div to the "class=" clear "style before the end of parent </div>". This clears the float.

3. Additional Labeling Method
This method should be the simplest one, and the proposal to add a "clear:both" element at the end of the container
Force the container to fit its height so that all the float elements are loaded.
<div id= "Main" >
<div id= "left" ></div>
<div id= "right" ></div>
<div class= "Clear" ></div>
</div>
<div id= "Footer" ></div>

. Clear{clear:both;}

4. Add Overflow:hidden to parent element;
Note: If the child element uses the positioning layout, it will be difficult to implement.

5. Using pseudo-objects after methods
Defines a class that uses pseudo-objects after, to control the impact of floating elements.
The most popular clear floating code on the Web:
. clearfix:after{
Clear:both;
Display:block;
Visibility:hidden;
height:0;
line-height:0;
Content: ";

}
. clearfix{zoom:1;}/* Resolve IE6/7 compatibility issues */

@copy from http://www.cnblogs.com/zzwlovegfj/archive/2012/08/12/2634313.html

Div+css's 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.