绝对位置绝对位置 [英] Absolute positioning inside absolute position
问题描述
我有3个 div
元素。
第一 div
第二 div
绝对位于第一个 div
相对定位(并包含在第一个 div
中)
第三 div
包含在第二 div
也有绝对定位。
< div id =1st>
< div id =2nd>
< div id =3rd>< / div>
< / div>
< / div>
为什么第三个 div
第二 div
(也是第一 div
的绝对位置),而不是第一因为第三个
div
是绝对定位到
div
position:absolute 会重置 position:relative c>的相对位置。
没有办法解决这个问题 - 如果你想要第三个 div
相对于第一个绝对地定位,你必须使它成为第一个的孩子。
I have 3 div
elements.
1st div
is bigger (wrap) and has position:relative;
2nd div
is positioned absolute to the 1st div
relative positioning (and is included in the 1st div
)
3rd div
is contained in the 2nd div
and also has absolute positioning.
<div id="1st">
<div id="2nd">
<div id="3rd"></div>
</div>
</div>
Why is the 3rd div
position absolute to the 2nd div
(which is also absolute position to the 1st div
) and not to 1st div
that has relative position ?
Because the 3rd div
is absolute positioning to the absolute positioned 2nd div
.
Because position: absolute
resets the relative position for children just as position: relative
does.
There is no way around this - if you want the third div
to be absolutely positioned relatively to the first one, you will have to make it a child of the first one.
这篇关于绝对位置绝对位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!