父级元素position:absolute,子节点也是absolute

时间:2025-01-06 19:36:26

当父级属性position是absolute,子节点也是absolute的时候,子节点是相对父级absolute的,举个例子

<div class="headManage">

<a href="javascript:;" class="guanli">

<div class="bg"></div>

<span class="index_bg">管理照片</span>

</a>

</div>

.headManage{position: relative;}

.guanli{position: absolute;top:116px;left:0;}
.guanli .bg{position: absolute;top:116px;left:0;}
.guanli .index_bg{position: absolute;top:116px;left:0;}

父级元素position:absolute,子节点也是absolute

正确应该是:

<div class="headManage">

<a href="javascript:;" class="guanli">

<div class="bg"></div>

<span class="index_bg">管理照片</span>

</a>

</div>

.headManage{position: relative;}

.guanli{position: absolute;top:116px;left:0;}
.guanli .bg{position: absolute;top:0;left:0;}
.guanli .index_bg{position: absolute;top:0;left:0;}

父级元素position:absolute,子节点也是absolute