Skip to content

Packs / web-development-public

navbar-header

Sticky site header that turns solid with a blur on scroll, hides on scroll down and returns on scroll up, plus an accessible mobile drawer (aria-expanded, Esc to close, focus moves in). Plain HTML/CSS/JS.

Install

logicpacks pack use web-development-public/navbar-header
get_pack web-development-public/navbar-header

The second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.

Keys it needs (names only)

None.

Playbooks included

  • Spec: spec/SPEC.md (goal, steps, edge cases, don’ts)
  • Routes: static-local
  • Checks: 1 in outcome/checks.yaml
  • Code: _shots/shot-1280-rm.png_shots/shot-1280.png_shots/shot-390-rm.png_shots/shot-390.pngindex.htmlnav.jsstyle.css
  • Tools: python3, playwright-python, chromium

Usage, last 8 weeks

New: no recorded use yet.

Purpose (from spec/SPEC.md)

Goal

A header that works on every page of a marketing site: readable over a hero image or video, solid once the user scrolls, out of the way while reading, and fully usable on a 390 px phone with a keyboard or screen reader.

Steps

  1. Copy code/index.html (header markup only), code/style.css (the .site-header to .nav-drawer rules) and code/nav.js.
  2. Set brand name, links and the primary CTA. Keep at most 5 top-level links; move the rest into the footer.
  3. Tune the tokens at the top of style.css: --bg, --fg, --accent, --header-h.
  4. Keep the three states driven by data attributes: data-state="top|scrolled" (transparent vs solid + blur after 24 px) and data-hidden (hide on scroll down past 240 px, show on any scroll up).
  5. Mobile (<= 860 px): links and actions collapse into the toggle. The toggle sets aria-expanded, swaps its label, opens #nav-drawer, locks body scroll and moves focus to the first link. Esc closes and returns focus to the toggle; tapping a link closes it.
  6. Add html { scroll-padding-top } equal to the header height so anchor links are not hidden under the fixed header.
  7. Run the outcome checks.

Edge cases

  • Header over a light hero: start with dark text or add a subtle top gradient; test contrast in the top state.
  • Never hide the header while the drawer is open, near the top of the page, or with prefers-reduced-motion: reduce.
  • iOS Safari: backdrop-filter needs the -webkit- prefix; keep a semi-opaque background as the fallback.
  • Resize from mobile to desktop with the drawer open: the media-query listener closes it.
  • Long brand names: the brand must not push the toggle off-screen at 390 px (no horizontal scroll check).

Don'ts

  • No hamburger on desktop when the links fit.
  • No duplicate controls for the same job (one menu button, one CTA).
  • Do not animate layout properties on scroll (only transform and colors); do not attach unthrottled scroll handlers (use rAF).