설명을 찾을 수없는 이상한 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
이 적용될 때 그 요소가 위에 나타나는 이유는 무엇입니까?
답장을 보내 주셔서 감사합니다! 문서가 "절대 값"또는 "상대 값"* 및 "자동"* 이외의 Z- 인덱스 값을 갖는 요소를 말하기 때문에 조금 혼란 스럽습니다. (강조 광산). 필자는'position'을'relative '로 정의했기 때문에'z-index'는 초기 값인'auto'이어야합니다. 왜 새로운 스태킹 여전히 컨텍스트 양식을합니까? – Sven