是否可以在同一个 div 中使用不同的 z-index?

Is it possible to have different z-index in the same div?

我正在尝试使用两次相同的文本,一个在另一个之上。这段文字被图片截断了。

这些文本位于同一个居中 div 中,但它们的 z-index 保持不变。

我试图更改元素的任何 z-index。

.bottom {
  font-family: Gotham;
  font-style: normal;
  font-weight: 900;
  font-size: 144px;
  color: #ededed;
  position: absolute;
}

.up {
  font-family: Gotham;
  font-style: normal;
  font-weight: 900;
  font-size: 144px;
  color: transparent;
  -webkit-text-stroke: #ededed 2px;
  z-index: 2;
  position: absolute;
}

.group {
  position: relative;
  width: 465.125px;
  height: 144px;
  left: 50%;
  right: 50%;
  transform: translate(-50%, -50%);
  margin-top: 30%;
  z-index: 1;
}
<div class="group">
  <p class="up">ZAIUS</p>
  <p class="bottom">ZAIUS</p>
</div>

我想要图片下方的填充文字和笔画文字。 笔划文本应该在另一个和图像之上。

我对 z-index 了解不多,但是如果我理解正确的话,从 .up 中删除 z-index 并将位置更改为相对的工作。

.bottom {
  font-family: Gotham;
  font-style: normal;
  font-weight: 900;
  font-size: 144px;
  color: #ededed;
  position: absolute;
}

.up {
  font-family: Gotham;
  font-style: normal;
  font-weight: 900;
  font-size: 144px;
  color: transparent;
  -webkit-text-stroke: #ededed 2px;
  position: relative;
}

.group {
  position: relative;
  width: 465.125px;
  height: 144px;
  left: 50%;
  right: 50%;
  transform: translate(-50%, -50%);
  margin-top: 30%;
  z-index: 1;
}
<div class="group">
  <p class="up">ZAIUS</p>
  <p class="bottom">ZAIUS</p>
</div>

我看不出这里有什么问题,只需为描边元素指定更高的值即可 z-index。另外,您可能会因为文本的颜色和笔画相同而感到困惑。我尝试演示它 HERE

根本不需要 z-index 属性 来实现您的目标,如下例所示。

此外,应尽可能省略 z-index 以保持代码清洁、可重用、可维护和可扩展。
当然,在非常小的项目中,它不如在大项目中重要。

#frame {
  position: relative;
  width: 100%;
  height: 100%;
}

.group {
  position: absolute;
  width: 400px;
  height: 250px;
  left: 10%;
  top: 30%;
}

.group img {
  position: absolute;
  top: 0;
  left: 70%;
}

.big-letters {
  font-family: Gotham;
  font-style: normal;
  font-weight: 900;
  font-size: 144px;
  position: absolute;
  top: 0;
  left: 0;
}

.bottom {
  color: #ededed;
}

.up {
  color: transparent;
  -webkit-text-stroke: #ededed 2px;
}
<div id="frame">
  <div class="group">
    <div class="big-letters bottom">LOREM</div>
    <img src="https://via.placeholder.com/300x200"/>
    <div class="big-letters up">LOREM</div>
  </div>
</div>