Skip to main content

Box Shadows and Animation on Hover - CSS

Smooth animation card effect using box shadow with only CSS animations and a pseudo element. Hover over the box below to see the action.

DEMO

HTML

<div class="box-shadow"></div>

CSS

.box-shadow {
  position: relative;
  display: inline-block;
  width: 100px;
  height: 100px;
  border-radius: 5px;
  background-color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  transition: all 0.3s ease-in-out;
  margin: 1em;
  background-color: BlanchedAlmond;
}

.box-shadow::after {
  content: '';
  position: absolute;
  z-index: -1;
  width: 100%;
  height: 100%;
  opacity: 0;
  border-radius: 5px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
  transition: opacity 0.3s ease-in-out;
}

.box-shadow:hover {
  transform: scale(1.2, 1.2);
}

.box-shadow:hover::after {
  opacity: 1;
}

Comments