私は説明が見つからない奇妙なCSSを見つけました。 position: absolute
を使用CSS配置:相対的な影響z-インデックスのない積み重ね順
、div
は、別div
B上方に引っ張られます。 div
b(の場合は)は、子がposition: relative
である場合、その要素はのの上に表示されます。
var parent = document.querySelector('.parent')
document.querySelector('button').addEventListener('click', function() {
\t parent.classList.toggle('toggle-class')
});
.parent {
background: grey;
height: 100px;
position: relative;
}
.child-a {
background: orange;
position: absolute;
width: 100%;
height: 100%;
text-align: center;
}
.child-b {
background: green;
height: 100%;
}
.toggle-class .child-b span {
position: relative;
}
<div class="parent">
<div class="child-a">
child a
</div>
<div class="child-b">
<span>child b' child</span>
</div>
</div>
<button>
toggle
</button>
私の最初の反応は、コンテキストをスタック上に読み込むことだったが、ないz-index
が遊んでないので、これはおそらくポジショニングとは何かを持っています。それでも、私はこれがどのように可能であるか理解していません - なぜposition: relative
が適用されると、上記の要素が上に現れますか?
ありがとうございました!私はちょっと混乱しています。なぜなら、ドキュメントでは、「絶対値」または「相対値」*と「auto」*以外のz-インデックス値を持つ要素が ' (強調する鉱山)。私は 'position'を' relative'と定義しているだけなので、 'z-index'は初期値、' auto'でなければなりません。新しいスタッキングがまだコンテキスト・フォームになっているのはなぜですか? – Sven