AI CSS Animations

Skewed Background Nav Hover Effect

A slanted block of color sweeps in from the left behind the hovered item and leaves out the right, so running along the menu feels like one bar passing through.

Also known as: slanted nav hover, skew background menu, parallelogram hover css.

HTML

<nav class="hfx-nav-skew-fill">
  <a href="#">Home</a>
  <a href="#">Menu</a>
  <a href="#">Order</a>
  <a href="#">Visit</a>
</nav>

CSS

.hfx-nav-skew-fill {
  --c: var(--hfx-color, #3b82f6);
  display: flex;
  align-items: center;
  font: 600 var(--hfx-size, 16px)/1.2 system-ui, sans-serif;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.04em;}
.hfx-nav-skew-fill a {
  position: relative;
  isolation: isolate;
  padding: 0.6em 1em;
  color: inherit;
  text-decoration: none;
  transition: color 0.3s ease;
}
.hfx-nav-skew-fill a::before {
  content: "";
  position: absolute;
  inset: 0.15em 0;
  z-index: -1;
  background: var(--c);
  transform: skewX(-14deg) scaleX(0);
  transform-origin: right;
  transition: transform 0.35s cubic-bezier(0.65, 0, 0.35, 1);
}
.hfx-nav-skew-fill a:is(:hover, :focus-visible) { color: #fff; }
.hfx-nav-skew-fill a:is(:hover, :focus-visible)::before {
  transform: skewX(-14deg) scaleX(1);
  transform-origin: left;
}

@media (prefers-reduced-motion: reduce) {
  .hfx-nav-skew-fill, .hfx-nav-skew-fill *, .hfx-nav-skew-fill::before, .hfx-nav-skew-fill::after, .hfx-nav-skew-fill *::before, .hfx-nav-skew-fill *::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

Sliding Pill Nav Hover Effect
Directional Underline Nav Hover Effect
Dot Indicator Nav Hover Effect
Vertical Nav Indicator Hover Effect