โœฆ StealThis .dev

Navigation Menu

Horizontal navigation bar with mega-menu dropdowns, animated indicator underline, mobile hamburger collapse, and keyboard accessibility.

Open in Lab
css vanilla-js
Targets: JS HTML

Code

A production-ready horizontal navigation bar with a mega-menu dropdown, animated active indicator, and responsive mobile hamburger. No dependencies.

Features

  • Fixed top navbar with backdrop-filter: blur
  • โ€œProductsโ€ item reveals a 2ร—2 mega-menu grid of product cards
  • Animated underline indicator slides smoothly between active nav items
  • Mobile: hamburger toggles a vertical stacked nav below the bar
  • Closes on outside click or Escape

How it works

  1. Mega-menus are position: absolute panels below their trigger item, hidden with opacity: 0 + pointer-events: none until .open
  2. The active indicator is a position: absolute <span> that updates its left and width via JS on hover/focus
  3. Mobile hamburger toggles a .mobile-open class on the nav; items stack vertically via flexbox
  4. ResizeObserver resets mobile state when the viewport widens past the breakpoint

Accessibility

  • Nav uses <nav> landmark with aria-label
  • Mega-menu trigger uses aria-haspopup="true" and aria-expanded
  • All interactive items are keyboard-reachable; Enter/Space toggles dropdowns