Resolution of element Margin-top invalidation in div tag
Element superior tag is Div, has set the width and height and other properties, but, in the element using margin to adjust the time, can not be effective, the following is a good solution, interested friends can refer to the next title.
The problem is very wonderful. The element ancestor tag is a Div, which has set the properties of width and height, but cannot take effect when adjusting the element using margin. Student experience Tip, set the parent element property of the element to
Overflow:hidden; Solutions to Margin-top transfer problems in nested div
In both browsers, there are two nested relationship div, if the outer div's parent element padding value is 0, then the value of the inner div's margin-top or margin-bottom will be "transferred" to the outer div.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<body>
<div style= "width:300px; height:100px "> Upper layer </div>
<div style= "width:300px; Height:300px;overflow:hidden "> <!--parent Layer--
<div style= "margin:50px; width:200px; height:200px "" > sub-layer </div>
</div>
</body>
Reason: The box did not get haslayout caused margin-top invalid
Workaround:
1, in the parent div plus: overflow:hidden;
2, the outer margin of the margin-top is changed into the padding-top inner margin;
3. The parent element produces a margin overlapping edge with a border that is not 0 padding or width is not 0 and style is not a none.
Parent-level div plus: padding-top:1px;
4, let the parent element generate a block formating context, the following properties can be implemented
* Float:left/right
* Position:absolute
* Display:inline-block/table-cell (or other table type)
* Overflow:hidden/auto
Parent-level div plus: position:absolute;
Margin-top failure in Div