Box-Shadow 需要保持在所有玩家面前

Box-Shadow Needed to Stay in Front of all lLayers

我创建了一个可滚动的项目列表。该列表顶部有一个标题部分,并使用 box-shadow 覆盖在列表顶部。当我为列表项添加高亮悬停效果时,列表项高亮变为 box-shadow 的 in-front。有没有办法让 box-shadow 始终显示 in-front?

提供的示例: https://codepen.io/jwaugh3/pen/WNbopGX

```
<div class="gameList">
          <div class="gameListTitle">
            <h1>Title Block</h1>
            <h2>Box-Shadow Below</h2>
          </div>
        <div class="scroller">
          <div class="force-overflow">
          <div class="gameTile">
            <h class="gameTileText gameTimeGrid">*GameTime*</h>
            <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
            <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
            <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
            <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
            <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
          </div>
          <div class="gameTileSpacer"></div>
    </div>
</div>
```


.gameList {
  grid-column-start: 1;
  grid-column-end: 2;
  grid-row-start: 2;
  grid-row-end: 4;
  background-color: #6B6B6B;
  border-radius: 10px;
}

.gameListTitle {
  z-index: 1;
  border-radius: 10px 10px 0px 0px;
  background-color: #6B6B6B;
  color: white;
  padding: 10px;
  box-shadow: 0px 10px 6px -1px rgba(0,0,0,0.58);
}

.scroller {
  overflow-y: scroll;
  height: 85%;
  margin-right: 2px;
  width: 100%;
}

::-webkit-scrollbar {
  margin-top: 10px;
    width: 12px;
    background-color: rgb(0,0,0,0);
}

::-webkit-scrollbar-track {
  margin-top: 10px;
  margin-bottom: 10px;
  background-color: rgb(0,0,0,0);
  box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  margin-top: 10px;
  margin-bottom: 10px;
  background: white;
  box-shadow: inset 0 0 6px rgba(0,0,0,.3);
  border-radius: 10px;
}

.force-overflow {
  margin-right: 3px; /*margin added to right of list for scrollbar overlap*/
}

.gameTile {
  padding: 10px;
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-columns: 1fr 1fr;
}

.gameTile:hover {
  background-color: #A0A0A0;
  z-index: 1;
}

.gameTileText {
  font-size: 1rem;
  font-weight: bold;
  color: white;
  padding: 3px;
  vertical-align: middle;
}

.teamIcon {
  max-width: 25px;
}

.gameTimeGrid {
  grid-row-start: 1;
  grid-row-end: 2;
  grid-column-start: 1;
  grid-column-end: 2;
}

.tournamentNameGrid {
  grid-row-start: 1;
  grid-row-end: 2;
  grid-column-start: 2;
  grid-column-end: 3;
}

.teamOneGrid {
  grid-row-start: 2;
  grid-row-end: 3;
  grid-column-start: 1;
  grid-column-end: 2;
}

.teamOneScoreGrid {
  grid-row-start: 2;
  grid-row-end: 3;
  grid-column-start: 2;
  grid-column-end: 3;
  text-align: center;
}

.teamTwoGrid {
  grid-row-start: 3;
  grid-row-end: 4;
  grid-column-start: 1;
  grid-column-end: 2;
}

.teamTwoScoreGrid {
  grid-row-start: 3;
  grid-row-end: 4;
  grid-column-start: 2;
  grid-column-end: 3;
  text-align: center;
}

.gameTileSpacer {
  width: 100%;
  height: 3px;
  background-color: #2D2D2D;
}
```

所以你想在第一个列表项上重叠阴影?

您可以像这样向第一个列表项悬停添加插入阴影:

.gameTile:first-child:hover {
  background-color: #A0A0A0;
  z-index: 1;
  box-shadow: inset 0px 10px 6px -1px rgba(0,0,0,0.58);
}

您正在使用 CSS 网格,您需要做的就是将 display:grid 添加到 .gameList 中,这似乎丢失了?

.gameList {
  grid-column-start: 1;
  grid-column-end: 2;
  grid-row-start: 2;
  grid-row-end: 4;
  background-color: #6B6B6B;
  border-radius: 10px;
  
  display: grid /* Added */
}

/* z-index :1 */
.gameListTitle {
  z-index: 1;
  border-radius: 10px 10px 0px 0px;
  background-color: #6B6B6B;
  color: white;
  padding: 10px;
  box-shadow: 0px 10px 6px -1px rgba(0, 0, 0, 0.58);
}

/* no z-index or lower than .gameListTitle z-index*/
.scroller {
  overflow-y: scroll;
  height: 85%;
  margin-right: 2px;
  width: 100%;
}

::-webkit-scrollbar {
  margin-top: 10px;
  width: 12px;
  background-color: rgb(0, 0, 0, 0);
}

::-webkit-scrollbar-track {
  margin-top: 10px;
  margin-bottom: 10px;
  background-color: rgb(0, 0, 0, 0);
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  margin-top: 10px;
  margin-bottom: 10px;
  background: white;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, .3);
  border-radius: 10px;
}

.force-overflow {
  margin-right: 3px;
  /*margin added to right of list for scrollbar overlap*/
}

.gameTile {
  padding: 10px;
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-columns: 1fr 1fr;
}

.gameTile:hover {
  background-color: #A0A0A0;
  z-index: 1;
}

.gameTileText {
  font-size: 1rem;
  font-weight: bold;
  color: white;
  padding: 3px;
  vertical-align: middle;
}

.teamIcon {
  max-width: 25px;
}

.gameTimeGrid {
  grid-row-start: 1;
  grid-row-end: 2;
  grid-column-start: 1;
  grid-column-end: 2;
}

.tournamentNameGrid {
  grid-row-start: 1;
  grid-row-end: 2;
  grid-column-start: 2;
  grid-column-end: 3;
}

.teamOneGrid {
  grid-row-start: 2;
  grid-row-end: 3;
  grid-column-start: 1;
  grid-column-end: 2;
}

.teamOneScoreGrid {
  grid-row-start: 2;
  grid-row-end: 3;
  grid-column-start: 2;
  grid-column-end: 3;
  text-align: center;
}

.teamTwoGrid {
  grid-row-start: 3;
  grid-row-end: 4;
  grid-column-start: 1;
  grid-column-end: 2;
}

.teamTwoScoreGrid {
  grid-row-start: 3;
  grid-row-end: 4;
  grid-column-start: 2;
  grid-column-end: 3;
  text-align: center;
}

.gameTileSpacer {
  width: 100%;
  height: 3px;
  background-color: #2D2D2D;
}
<div class="gameList">
  <div class="gameListTitle">
    <h1>Title Block</h1>
    <h2>Box-Shadow Below</h2>
  </div>
  <div class="scroller">
    <div class="force-overflow">
      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

      <div class="gameTile">
        <h class="gameTileText gameTimeGrid">*GameTime*</h>
        <h class="gameTileText tournamentNameGrid">*TournamentName, Year*</h>
        <h class="gameTileText teamOneGrid"><img src="../resources/Griffinlogo_square.png" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamOneScoreGrid">*SeriesScore*</h>
        <h class="gameTileText teamTwoGrid"><img src="../resources/IG.jpg" class="teamIcon">*TeamName*</h>
        <h class="gameTileText teamTwoScoreGrid">*SeriesScore*</h>
      </div>
      <div class="gameTileSpacer"></div>

    </div>
  </div>
</div>

为什么有效?

The z-index property sets the z-order of a positioned element and its descendants or flex items.

定位元素:是位置属性被设置为非静态值的元素

弹性项目: 是弹性容器 display:flex; 或网格容器 display:grid;

的子元素

现在您在 .gameListTitle 上的 z-index:1 将生效。