Advertisement

Dropdown Navigation

| by Vladimir | 2 min read | code by Arby
A11y Ready Intermediate

See the Pen Dropdown Navigation.

Tech & Dependencies

HTML CSS
open-props remixicon normalize-css

Features

  • CSS Layers
  • Responsive Design
  • Mega Menu
  • Open Props

Browser Support

Chrome 99+ Edge 99+ Firefox 97+ Safari 15.4+

Core

Navigation is the backbone of usability, but traditional dropdowns can feel cramped and elusive. This component expands the concept of a menu into a panoramic dashboard. It is not just a list of links; it is a structured map of your application’s architecture.

Core Technique

The architecture utilizes the power of CSS Layers (@layer) and Open Props for a maintainable, conflict-free stylesheet.

  • Zero JavaScript Logic: The entire dropdown mechanism functions purely on CSS hover and focus states (.NavItem:hover, .NavItem:focus-within). This ensures zero lag and perfect accessibility for keyboard navigation.
  • CSS Layers: Styles are compartmentalized into layers (base.normalize, base.app, base.components). This modern approach prevents specificity wars, making it easy to drop this component into any existing codebase without style leakage.
  • Responsive Fluidity: The layout adapts gracefully. On desktop (>1024px), it is a hover-triggered mega menu. On mobile, it transforms into a horizontal scrollable strip (overflow-x: auto), maintaining accessibility without complex hamburger menu scripts.

Customization

The design system relies on Open Props variables, making global changes trivial.

Changing the Brand Color

@layer base.normalize-overrides {
  :root {
    /* Use an OKLCH color for modern vibrancy */
    --brand: oklch(64% 0.24 18); 
  }
}

Adjusting Menu Timing. Control how quickly the menu reveals itself to make it feel snappier or more relaxed.

.ItemContent {
  /* Speed up transition to 0.1s for a faster feel */
  transition: 0.2s ease; 
}

Browser Support

The component uses @layer and nested CSS, which are supported in all modern major browsers. Older browsers will ignore the layered organization but may struggle with nesting if not transpiled.

Advertisement