2017-10-04 7 views
0

z-index:-1を絶対子にすると、祖父母の下にdivが作成されます。どのように私は絶対的な子供を親のdivの下に行くようにするのですか?ここでzインデックスが-1の要素は、祖父母のdivの下にあります。

.grandparent{ 
 
    background:rgba(0, 128, 0, 0.89); 
 
    width:500px; 
 
} 
 

 
.parent{ 
 
    position:relative; 
 
    width:200px; 
 
    height:200px; 
 
    background:yellow; 
 
} 
 

 
.absolute-child{ 
 
    position:absolute; 
 
    width:100px; 
 
    height:100px; 
 
    background:red; 
 
    top:10px; 
 
    right:-50px; 
 
    z-index:-1; 
 
}
<div class="grandparent"> 
 
    <div class="parent"> 
 
     <div class="absolute-child"> absolute ch 
 
     </div> 
 
     <div class="siblings">siblings</div> 
 
    </div> 
 
</div

+0

あなたは私の答えが役に立ったと評価していた場合、あなたはそれを私のために少し説明することができ、チェック(参考になっ) –

+0

@AwsmeSandyとしてそれをマークしてください?または、自分自身を明確にするための記事を教えてください。 –

+1

2つの要素でZ-インデックスを再生している場合、親インデックスにもz-indexを付けることができます。そのため、祖父母のZ-インデックスは子divのベースとして機能します。 –

答えて

1

何をしたいですが、それについてz-index: 0;作業はとてもgranparentにposition: relative;を追加しました。

.grandparent{ 
 
    background:rgba(0, 128, 0, 0.89); 
 
    width:500px; 
 
     z-index: 0; 
 
    position: relative; 
 
} 
 

 
.parent{ 
 
    position:relative; 
 
    width:200px; 
 
    height:200px; 
 
    background:yellow; 
 
} 
 

 
.absolute-child{ 
 
    position: absolute; 
 
    width: 100px; 
 
    height: 100px; 
 
    background: red; 
 
    top: 10px; 
 
    right: -50px; 
 
    z-index: -1; 
 
}
<div class="grandparent"> 
 
    <div class="parent"> 
 
     <div class="absolute-child"> absolute ch 
 
     </div> 
 
     <div class="siblings">siblings</div> 
 
    </div> 
 
</div

関連する問題