【发布时间】:2018-11-02 03:01:26
【问题描述】:
我的位置有问题:sticky 和 z-index
我希望我的粘性元素中的模态被叠加层覆盖。 使用 position: relative 它可以工作:模态在覆盖之前。但是当我使用 Sticky 时,模态框位于覆盖层后面。
希望我的意思可以理解。 示例如下:
.sticky {
position: sticky; /* <-- dosen't work */
/* position: relative; /* <-- work */
top: 0;
width: 100%;
height: 200vh;
background: red;
}
.modal {
z-index: 1000;
position: fixed;
margin: 0 auto;
width: 200px;
height: 200px;
background: yellow;
margin: 0 auto;
}
.overlay {
z-index: 999;
position: fixed;
width: 100%;
height: 100%;
background: green;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0.75;
}
<div class="overlay"></div>
<div class="sticky">
<div class="modal">modal</div>
</div>
【问题讨论】:
-
您介意添加一个外观示例吗?
-
像这样:codepen.io/anon/pen/NOQVbG(位置:粘性替换为相对)
标签: html css css-position z-index