Child elements use the float parent element to open the method

Source: Internet
Author: User

A div contains a number of sub-div, and the child Div uses a floating, the parent Div can not be open, such as:

Some of the code is as follows:

1 <style>
2 #div1 {border:1px solid red;float:left;}
3 #div2, #div3 {float:right;border:1px solid blue;}
4 </style>
5
6 <div id= "Div1" >
7 <div id= "Div2" >two</div>
8 <div id= "Div3" >one</div>
9 </div>

If you want to open the parent element, you can use the following methods:

Method One:

The parent element is set overflow and zoom with the following styles:

1 <style>
2 #div1 {border:1px solid red;overflow:hidden;zoom:1;}
3 #div2, #div3 {float:right;border:1px solid blue;}
4 </style>

Method Two:

The parent element is also a floating effect, styled as follows:

1 <style>
2 #div1 {border:1px solid red;float:left;}
3 #div2, #div3 {float:right;border:1px solid blue;}
4 </style>

One drawback of this approach is that the width of the parent element needs to be set.

Method Three:

Add a child element and set the clear style:

1 <div id= "Div1" >
2 <div id= "Div2" >two</div>
3 <div id= "Div3" >one</div>
4 <div style= "Clear:both" ></div>
5 </div>

This method adds a DIV element, which in some cases may affect the traversal of the element.

The above method uses DOCTYPE HTML 4.0 and DOCTYPE XHTML 1.0 Transitional to test through the FF IE6 IE7 IE8, and no other browsers are tested.

Child elements use the float parent element to open the method

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.