Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling Divs - Drop Shadow through the middle of other div

I'm trying to create CSS styles that LOOK like a flip counter but don't actually function as one. I've got the general look and feel figured out, but I can't seem to get my box-shadow to overlap the display number.

This is what I have so far:

.numberwrapper {
  width: 50px;
  height: 90px;
  background-color: black;
  border-radius: 5px;
  position: relative;
  display: inline-block;
}
.shadow {
  width: 100%;
  height: 50%;
  z-index: 100;
  box-shadow: 0px 5px 4px -2px #888888;
}
.number {
  font-family: 'Tahoma', sans-serif;
  top: -90;
  color: #ffffff;
  font-size: 85px;
  line-height: 0px;
  text-align: center;
}
.bigcomma {
  font-family: 'Tahoma', sans-serif;
  font-size: 85px;
  color: black;
}
<div class="numberwrapper">
  <div class="shadow">
  </div>
  <div class="number">
    1
  </div>
</div>


<span class="bigcomma">,</span>
<div class="numberwrapper">
  <div class="shadow">
  </div>
  <div class="number">
    2
  </div>
</div>

<div class="numberwrapper">
  <div class="shadow">
  </div>
  <div class="number">
    3
  </div>
</div>

<div class="numberwrapper">
  <div class="shadow">
  </div>
  <div class="number">
    4
  </div>
</div>

Like I said, my biggest issue is that I can't get my .shadow div to show up on top of the number.

like image 716
theonlydidymus Avatar asked Nov 25 '25 22:11

theonlydidymus


1 Answers

Add "position: relative" to .shadow for the z-index to kick in:

.numberwrapper {
  width: 50px;
  height: 90px;
  background-color: black;
  border-radius: 5px;
  position: relative;
  display: inline-block;
}
.shadow {
  width: 100%;
  height: 50%;
  z-index: 100;
  box-shadow: 0px 5px 4px -2px #888888;
  position: relative;
}
.number {
  font-family: 'Tahoma', sans-serif;
  top: -90;
  color: #ffffff;
  font-size: 85px;
  line-height: 0px;
  text-align: center;
}
.bigcomma {
  font-family: 'Tahoma', sans-serif;
  font-size: 85px;
  color: black;
}
<div class="numberwrapper">
  <div class="shadow">
  </div>
  <div class="number">
    1
  </div>
</div>


<span class="bigcomma">,</span>
<div class="numberwrapper">
  <div class="shadow">
  </div>
  <div class="number">
    2
  </div>
</div>

<div class="numberwrapper">
  <div class="shadow">
  </div>
  <div class="number">
    3
  </div>
</div>

<div class="numberwrapper">
  <div class="shadow">
  </div>
  <div class="number">
    4
  </div>
</div>
like image 83
lampyridae Avatar answered Nov 28 '25 12:11

lampyridae



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!