Search code examples
htmlcssbox-shadow

Box-Shadow Needed to Stay in Front of all lLayers


I have created a list of items that are scrollable. The list has a title section at the top and uses a box-shadow that overlays on top of the list. When I add a highlight hover effect to the list items, the list item highlight goes in-front of the box-shadow. Is there a way to have the box-shadow always show in-front?

Example provided: 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;
}
```

Solution

  • You're using CSS Grid all you need to do is add display:grid to .gameList which seems to be missing ?

    .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>

    Why does it work ?

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

    Positioned element: is an element who's position property is set to a value other than static

    Flex item: is an child element of a flex container display:flex; or a grid container display:grid;

    Now your z-index:1 on .gameListTitle will be effective.