我有一个关于 div 相对定位对齐的问题。
我想让第二个 div 在位置上固定不变,即使我移除第一个 div。但问题是,当我移除第一个 div 时,第二个 div 会调整其位置。
我的问题是,如何使第二个 div 的位置不受第一个 div 移除的影响呢?谢谢 :)
这是代码:
<div style="border: 1px solid red;width:400px;height:150px;margin:0px auto;" >
<div style="border: 1px solid red; position: relative;
width: 262px; height: 20px; top: 20px; left: 20px;">div-1</div>
<div style="border: 1px solid red; position: relative;
width: 262px; height: 20px; top: 60px; left: 20px;">div-2</div>
</div>
将输出:
然后,如果第一个div被移除,第二个div会自动调整其位置。这段代码:
<div style="border: 1px solid red;width:400px;height:150px;margin:0px auto;" >
<div style="border: 1px solid red; position: relative;
width: 262px; height: 20px; top: 60px; left: 20px;">div-2</div>
</div>
将会输出: