The parent div cannot be opened when the sub-div is set to float ., Div settings floating support

Source: Internet
Author: User

The parent div cannot be opened when the sub-div is set to float ., Div settings floating support

<Div class = "mainBox"> <div class = "leftBox"> </div> <div class = "rightBox"> </div> <div class = "clear"> </div>

 

Note: After leftBox and rightBox are set to float, they are out of the normal Document Stream and no longer occupy the positions in the original document. Therefore, the parent div cannot be opened.

Solution:

① You can set the parent div height to PX to make the leftBox and rightBox on the page look "as if" still in the original position. ② define a class selector and set clear: both; clear floating. To solve the div height problem in IE6, you can add the attribute height: 0; overflow: hidden;
. MainBox {width: 960px; margin: 0 auto; background-color: # CFF; overflow: visible ;}. leftBox {width: 740px; height: 300px; background-color: # C9F; float: left ;}. rightBox {width: 210px; height: 300px; background-color: # FCF; float: right ;}. clear {clear: both; height: 0;/* solves IE6 height problems */overflow: hidden ;}

/* If the parent element does not set the height and the child element has a height, the parent element will be opened * // * if the child element is set to float, it will be out of the Document Stream, the parent element is not supported * // *. Therefore, the child element is set to floating, and the parent element needs to be set to height */

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.