我有以下html。我在可滚动的div容器中有多个元素(例如id为id,1、2、3的div)。
在每个元素中,我需要使用css位置“ absolute”,该位置与其父div有关(即class ='Anchor')。
我遇到的问题是,当我滚动外部容器时,没有移动绝对位置的div。我的理解是位置“绝对”是相对于其父DIV元素的位置。您能告诉我在滚动外部容器时如何使那些“绝对”位置移动吗?
<div style="overflow-y: scroll">
<div>
<div class="Anchor" id="one">
<div style="position: absolute"> something </div>
<div style="position: absolute"> something else </div>
<div>
<div class="Anchor" id="two">
<div style="position: absolute"> something </div>
<div style="position: absolute"> something else </div>
<div>
<div class="Anchor" id="three">
<div style="position: absolute"> something </div>
<div style="position: absolute"> something else </div>
</div>
</div>
</div>
您必须position: relative;
在父div上进行设置,以使子元素相对于其移动。
实际上,只要static
不使用默认位置,就可以将父div设置为任何用户定义的位置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句