这是我在修理布局时总是遇到的一个问题。我有一个绝对定位的DIV,我放置了一个儿童DIV,其中也需要绝对定位。但我真的希望这个孩子DIV相对于父母行为......这甚至有可能吗?或者我需要创建一个换行DIV?绝对定位DIV相对于(也绝对定位)父DIV的位置?
<div class="container" style="position:relative;">
<div class="parent" style="position:absolute;">
<!-- this child div will behave relative to .container -->
<div class="child" style="position:absolute;"></div>
</div>
</div>
这是“包装”的解决方案,我宁愿避免:
<div class="container" style="position:relative;">
<div class="parent" style="position:absolute;">
<div class="wrapper" style="position:relative;">
<!-- this child div will behave relative to .wrapper-->
<div class="child" style="position:absolute;"></div>
</div>
</div>
</div>