First look at the following code:
- <body style= "margin:0px;padding:0px;" >
- <div style= "Background-color: #FF0000;" >
- <div style= "Margin:10px;background-color: #00FF00;" >cftea</div>
- </div>
- </body>
This code shows the same results in each browser, and the following illustration shows a screenshot from Chrome:
This means that the margin-top is relative to the body, and the margin-left is relative to the outer div. Here said that relative to the body may not be accurate, such as the outermost set a table, it is relative to the table TD.
Now look at another piece of code:
- <body style= "margin:0px;padding:0px;" >
- <div style= "Width:100px;background-color: #FF0000;" >
- <div style= "Margin:10px;background-color: #00FF00;" >cftea</div>
- </div>
- </body>
For the outer div increased width, in Firefox, the effect is unchanged, in IE became such:
This shows that after specifying the width of the outer div, in IE, the inner div margin-top is relative to the outer div.
Finally, look at another piece of code:
- <body style= "margin:0px;padding:0px;" >
- <div style= "Position:absolute;background-color: #FF0000;" >
- <div style= "Margin:10px;background-color: #00FF00;" >cftea</div>
- </div>
- </body>
Change the width:100% to Position:absolute, at this time, the performance results are the same in each browser, the inner div margin-top, margin-left are relative outer Div, and the outer div width is no longer 100%, but tightening to paste Near the inner layer div's margin edge.