AI CSS Animations

Parallax Card Hover

The landscape in the card splits into layers that slide at different speeds: the sun rises, the far ridge barely moves, the near hills sweep past. Pure transforms on three stacked shapes.

Also known as: parallax hover effect css, layered image card, depth hover card.

Serra da Estrela

Three ridge walks above the clouds

HTML

<article class="hfx-card-parallax-layers">
  <div class="hfx-card-parallax-layers-scene">
    <span class="hfx-card-parallax-layers-sun"></span>
    <span class="hfx-card-parallax-layers-far"></span>
    <span class="hfx-card-parallax-layers-near"></span>
  </div>
  <div class="hfx-card-parallax-layers-body">
    <h3>Serra da Estrela</h3>
    <p>Three ridge walks above the clouds</p>
  </div>
</article>

CSS

.hfx-card-parallax-layers {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  width: 15em;
  border-radius: 0.75em;
  overflow: hidden;
  background: #fff;
  border: 1px solid color-mix(in srgb, #000 10%, transparent);
  color: #1f2937;
  font-family: system-ui, sans-serif;
  width: 13em;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.4s ease;}
.hfx-card-parallax-layers:hover {
  transform: translateY(-0.2em);
  box-shadow: 0 0.9em 1.4em -0.9em color-mix(in srgb, #000 35%, transparent);
}
.hfx-card-parallax-layers-scene {
  position: relative;
  height: 6.2em;
  overflow: hidden;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--c) 30%, #fff), color-mix(in srgb, var(--c) 12%, #fff7ed));
}
.hfx-card-parallax-layers-scene > span {
  position: absolute;
  transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.hfx-card-parallax-layers-sun {
  top: 2.3em;
  left: 58%;
  width: 1.8em;
  height: 1.8em;
  border-radius: 50%;
  background: #fde68a;
  box-shadow: 0 0 1em #fde68a;
}
.hfx-card-parallax-layers-far {
  inset: 1.2em -2em 0;
  background: color-mix(in srgb, var(--c) 45%, #fff);
  clip-path: polygon(0 62%, 14% 40%, 26% 55%, 42% 22%, 56% 48%, 70% 30%, 86% 52%, 100% 38%, 100% 100%, 0 100%);
}
.hfx-card-parallax-layers-near {
  inset: 3em -3em 0;
  background: color-mix(in srgb, var(--c) 80%, #000);
  clip-path: polygon(0 55%, 20% 30%, 38% 60%, 60% 20%, 80% 58%, 100% 35%, 100% 100%, 0 100%);
}
.hfx-card-parallax-layers:hover .hfx-card-parallax-layers-sun { transform: translateY(-1.2em); }
.hfx-card-parallax-layers:hover .hfx-card-parallax-layers-far { transform: translateX(-0.6em); }
.hfx-card-parallax-layers:hover .hfx-card-parallax-layers-near { transform: translateX(-2em); }
.hfx-card-parallax-layers-body { padding: 0.75em 0.95em 0.85em; }
.hfx-card-parallax-layers h3 {
  font-weight: 600;
  margin: 0 0 0.2em;
  font-size: 0.95em;
  transition: color 0.3s ease;
}
.hfx-card-parallax-layers:hover h3 { color: var(--c); }
.hfx-card-parallax-layers p {
  margin: 0;
  font-size: 0.78em;
  color: #6b7280;
}

@media (prefers-reduced-motion: reduce) {
  .hfx-card-parallax-layers, .hfx-card-parallax-layers *, .hfx-card-parallax-layers::before, .hfx-card-parallax-layers::after, .hfx-card-parallax-layers *::before, .hfx-card-parallax-layers *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar hover effects