我对容器查询非常热衷。终于,这个CSS特性已经在所有浏览器中实现了。但是,当我创建多个相邻的容器,并在其中一个中放置一个绝对定位的z-index元素时,后面的容器会覆盖这个元素。
- 菜单(位置:绝对,z-index:9)是深蓝色框的一部分,该框具有
容器类型:内联尺寸
- 但被轻蓝色框覆盖,该框也是
容器类型:内联尺寸
个案研究:
.block {
display: inline-block;
background-color: darkblue;
color: lightblue;
margin: 2px;
width: 100%;
}
.block.container {
container-type: inline-size;
}
.popout {
background-color: darkgreen;
color: lightgreen;
position: absolute;
z-index: 9;
}
hr {
margin-bottom: 4rem;
}
<div class="block">
<p>Some content in regular inline-block</p>
<div class="popout">
<p>Popping out of it.</p>
<p>Popping out of it.</p>
<p>Popping out of it.</p>
</div>
</div>
<div class="block">
<p>Some content in regular inline-block</p>
</div>
<hr />
<div class="block container">
<p>Some content in block with
<pre>container-type: inline-size;</pre>
</p>
<div class="popout">
<p>Popping out of it.</p>
<p>Popping out of it.</p>
<p>Popping out of it.</p>
</div>
</div>
<div class="block container">
<p>Some content in block with
<pre>container-type: inline-size;</pre>
</p>
</div>
https://codepen.io/gofix/pen/yLREXaN
如何应用容器类型而不引入新的绝对布局上下文。
我尝试给所有这些container-type: inline-size
一个较低的z-index,这样做“有点”有效,但我不想用z-index填满整个页面。