嗨,我对绝对定位的一些基础知识感到非常困惑。
<!DOCTYPE html>
<html>
<head>
<link href="http://yui.yahooapis.com/3.0.0/build/cssreset/reset-min.css" rel="stylesheet" type="text/css" />
<style>
#containingBlock {
position: relative;
background: green;
}
#abs {
position: absolute;
background: blue;
top: auto;
}
</style>
</head>
<body>
<div id="containingBlock">
<p>foo</p>
<div id="abs">bar</div>
</div>
</body>
</html>
使用上述标记,div#abs不会重叠foo段落。
我知道如果给top一个值0而不是auto,可以使它们重叠,但由于div#containingBlock没有填充,所以我认为auto和0会做同样的事情。
然而,如果段落和div#abs在源顺序中交换-使bar在foo之前- top:auto;正如我预期的那样工作。
任何解释都将不胜感激!
position:absolute
后,auto
的表现就像你已经设置了position:static
。这是正确的吗? - Dave Cauto
(初始值),则该框的顶部边距边缘将定位在其包含块的顶部内容边缘。”这是错误的吗? - Dave Cp
添加边距,自动定位的div将清除底部边距。 - clairesuzy