37:
If you think it should be like this:
That's wrong. The result is as follows:
Because there is a margin collapse in CSS, that is, the border collapse or overlap. For the upper and lower Divs, the preceding div's margin-bottom and the following div's margin-top will collapse, that is, the maximum value in the upper and lower margin will be taken as the display value, so in this sense:The designers of CSS and browsers hope that we can only set one of the top or bottom margin blocks if there are two parallel content blocks in the layout..W3school also stipulates that when two vertical outer margins meet, they form an outer margin. The height of the merged margin is equal to the larger of the two merged margins.
However, the parent DIV's inner DIV is explained in another CSS convention, that is:For an element with block-level sub-elements, if the element does not have a vertical border or fill, the height is the distance between the top and bottom border edge of its sub-element.. So for the Code:
1: <div class="father"></div>
The height of the father div is 0, because the content of the div cannot be opened. If it changes:
1: <div class="father">I am here.</div>
The height is the height of the text, because the text is holding the DIV.
In other words, a DIV and its sub-DIV pay special attention to the vertical border or fill, which is like a pot with a pot in it. Can you hold the pot inside? It mainly depends on the lid, vertical border or fill is the "lid ". There are at least three solutions:
1. You need to set the border for the parent div. Of course, you can set the border to transparent:
1: border:1px solid transparent
2: or
3: border-top:1px solid transparent
2,Add padding to parent DIV, or at least add padding-top;
1: padding:1px
2: or
3: padding-top: 1px;/* must be greater than 0 */
3. Add overflow: hidden to the parent DIV
1: over-flow:hidden;
Source: http://www.ido321.com/387.html
Css and margin Problems
Auto is automatic, that is, the default one! The upper-left corner should be margin:-50px 0 0-50px. You can try the effect. The following four parameters are top-right bottom left, and PX is pixel.
Css problems margin
Margin: 10px
Margin-top: 10px
Margin-left: 10px
Margin-right: 10px
Margin-bottom: 10px
The distance between the current tag and the parent tag.