CSS Clear Float

Source: Internet
Author: User

Clear floating mainly say three ways.

The first type: Clear:both

<style>. Clear{Clear:both;    }. F-left{float: Left;    }</style><Divclass= "outer">    <Divclass= "Div1 f-left">1</Div>    <Divclass= "Div2 f-left">2</Div>    <Divclass= "Div3 f-left">3</Div>    <Divclass= "Clear"></Div></Div>

For the first method:

Advantages: Simple, less code, good browser support, not prone to strange problems

Cons: To add a lot of empty div

The second type: parent element Add Overflow:hidden

<style>. Over-flow{Overflow:Hidden;    }</style><Divclass= "outer over-flow">//Add a class here<Divclass= "Div1 f-left">1</Div>    <Divclass= "Div2 f-left">2</Div>    <Divclass= "Div3 f-left">3</Div></Div>

The third type: after Pseudo class

<style>. Clearfix:after{content:'. ';Display:Block;Visibility:Hidden;Height:0;Line-height:0;font-size:0;Clear:both;}. Clearfix{Zoom:1;/* Main compatible ie*/}</style><Divclass= "Div1 clearfix">      <Divclass= "Left">Left</Div>       <Divclass= "Right">Right</Div> </Div>

For the third type: IE8 and non-IE browsers are supported: After, principle and method 2 somewhat similar, zoom (ie proprietary properties) can solve the ie6,ie7 floating problem.

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.