Height collapse problem (overflow and clear)

Source: Internet
Author: User

<! DOCTYPE html>


<meta charset= "UTF-8" >
<title> height collapse </title>
<style>
. box1{
border:5px solid red;
/* According to the standard, the attributes implied by the elements in the page are called BFC
* BFC, this property can be set to on and off, default is off
* When the element BFC is turned on, the element will have the following characteristics
* 1. The parent element's vertical margin does not overlap with child elements
* 2. Elements that open BFC are not covered by floating elements
* 3. The element that opens BFC can contain floating child elements
*
*/
/*
* How to open the BFC of elements
* 1. Set the float of the element
*-Open in this way, although the parent element can be opened, but will cause the width of the parent element to be lost
*-and using this method will also cause the bottom element to move up, not solve the problem
* 2. Set the absolute positioning of the element (2 with 1 effect)
* 3. Set element to Inline-block (effect not width)
* Not recommended in the above 3
* 4. Set the overflow of the element to a non-visible
*/
/*float:left;*/
/*position:absolute;*/
/*display:inline-block;*/
/*overflow:hidden; */
/*ie6 The following browsers, do not support BFC, but use the Haslayout
* The function is similar to BFC, so the IE6 browser can solve the problem by Haslayout.
* Display:inline-block
Height: (any value except Auto)
Width: (any value except Auto)
float: (left or right)
Position:absolute
Writing-mode:tb-rl
Zoom: (any value except normal)
The least useful:
Zoom
*
*
* */
/*zoom the meaning of amplification, followed by a number, write a few times to enlarge the element * *
/*zoom:3;*/

}
. box2{
width:100px;
height:200px;
Background-color: #000000;
Float:left;

}
. box3{
height:100px;
Background:green;
}
/*
*clear can be used to clear the effect of other floating elements on the current element
* Optional Value: None
* Left
* Right
* Both
*/
. clearfix:after{
/* Add a content */
Content: "";
/* Convert to a block element */
Display:block;
/* Clear both sides floating */
Clear:both;
}
</style>


<body>
<!--
In the document flow, the height of the parent element is the default of the quilt element.
That is, how high the child element is, and how high the parent element is.
However, when you set a float for a child element, the child element is completely detached from the document flow.
This will cause the child element to be unable to prop up the height of the parent element, causing the parent element's height to collapse
Because the height of the parent element collapses, all elements under the parent element move upward, which can cause the layout of the page to be cluttered

So we must avoid the problem of high collapse in the development.

Workaround:
1. The width and height of the parent element is written to death and is set on a wide height. (However, it is not recommended)
2. Turn on BFC
3. Add a blank div, set clear:both; clear float
-

<div class= "Box1 clearfix" >
<div class= "Box2" ></div>
</div>
<div class= "Box3" ></div>
<p> I am p paragraph </p>



</body>


Height collapse problem (overflow and clear)

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.