css - 覆盖的 z-index 问题

标签 css

我正在尝试添加叠加层,但它没有按预期工作。

.overlay {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: -1;
  width: 100%;
  height: 100%;
}
.center-div {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
}
<div class="center-div">
  <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
  </p>
</div>
<div class="overlay">

</div>

我需要带有类 center-div 的 div 位于带有类覆盖的 div 之上..

这是怎么回事?

最佳答案

.center-div 已经在 .overlay 之上了!

尝试将 background-color 添加到 .center-div 以突出显示它。

.overlay {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: -1;
  width: 100%;
  height: 100%;
}
.center-div {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  background-color: white;
}
<div class="center-div">
  <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
  </p>
</div>
<div class="overlay">

</div>

关于css - 覆盖的 z-index 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38202243/

相关文章:

javascript - 放大和缩小时 Chrome 中的表格行高和列表行高问题

css - Bootstrap CSS 表单类覆盖了提交按钮样式的 btn 类

javascript - 尝试水平对齐倒数计时器(第一次编码/构建)

css - 使用透明 div 淡出部分底部的文本,但在覆盖 div 后高度保持在部分下方

css - 框阴影和边框半径在 Facebook 的 Internet Explorer 中不起作用

css - Google Chrome 打印分页符

php - 我如何在购物车图标后面显示购物车中的总元素

c# - CSS:第一个选择器

javascript - 将javascript变量放入xsl属性

jquery - 如何在禁用 javascript 时使这些 jquery 弹出窗口回退到 css