跳到正文
cccskills
免费在 GitHub 公开

hambuger-menu

Use when you need to display a menu icon for mobile devices.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(2)

  • SKILL.md4.5 KB
  • references/pattern.md22.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Hamburger Menu

Display a menu icon for mobile devices

What it solves

Hamburger Menu is a three-line icon (☰) that toggles a hidden navigation panel, primarily on mobile and small-screen devices. Tapping or clicking the icon reveals the site's navigation, then hides it again when dismissed. This pattern conserves screen real estate on smaller viewports while keeping the full navigation accessible behind a single, universally recognized affordance.

When to use

Use Hamburger Menu to provide full navigation access on small screens without consuming permanent layout space. Common scenarios include:

  • Mobile or responsive websites where horizontal space is limited
  • Sites with extensive navigation that cannot fit in a single row on smaller screens
  • Progressive web apps that mimic native mobile app patterns
  • Responsive redesigns of desktop navigation menus
  • Admin dashboards or complex apps with many navigation items

When to avoid

  • Sites with only 3-4 navigation items that fit comfortably in a visible bar
  • Desktop-only applications where screen space is abundant
  • Kiosk or large-screen interfaces where discoverability is critical
  • Pages where the primary user task depends on navigation visibility (e.g., comparison tools)
  • When your analytics show users rarely find or use the hidden menu

Implementation workflow

  1. Confirm the pattern matches the problem and constraints before copying the example.
  2. Start from the anatomy and examples in references/pattern.md, then choose the smallest viable variation.
  3. Apply accessibility, performance, and interaction guardrails before layering visual polish.
  4. Use the testing guidance to verify behavior across keyboard, screen reader, responsive, and failure scenarios.

Accessibility guardrails

Do's ✅

  • Use a <button> element with aria-expanded and aria-controls
  • Trap focus inside the open panel so Tab cycles through menu items only
  • Close the menu on Escape key press and return focus to the toggle button
  • Use aria-label on the toggle to describe its current action ("Open menu" / "Close menu")
  • Announce state changes to screen readers via aria-expanded Don'ts ❌
  • Don't use a <div> or <span> as the toggle element
  • Don't allow focus to escape behind the open overlay
  • Don't remove visible focus indicators from menu links

Performance guardrails

Target Metrics

  • Toggle response: < 50ms visual feedback after tap/click
  • Panel animation: 250-300ms slide duration at 60fps
  • First interactive: Menu should be interactive within 100ms of toggle
  • Bundle size: < 3KB for hamburger component with styles (no heavy dependencies)
  • Paint cost: Use transform/opacity only for GPU-accelerated animations

Optimization Strategies

CSS-Only Toggle (Progressive Enhancement)

/* Use :has() or checkbox hack for no-JS base */
.nav-panel { transform: translateX(-100%); }
.hamburger-toggle[aria-expanded="true"] ~ .nav-panel {
  transform: translateX(0);
}

Common mistakes

Using Hamburger on Desktop

The Problem: Hiding navigation behind a hamburger icon on large screens reduces discoverability and forces unnecessary clicks.

How to Fix It: Only use the hamburger pattern below a responsive breakpoint (typically 768px or 1024px). Show full navigation on desktop.

Missing Focus Management

The Problem: When the menu opens, focus stays on the toggle or moves to the page body, leaving keyboard users stranded.

How to Fix It: Move focus to the first focusable element inside the panel on open. Trap focus within the panel. Return focus to the toggle on close.

No Escape Key Support

The Problem: Keyboard users have no way to quickly dismiss the menu without tabbing to a close button.

How to Fix It: Listen for the Escape key and close the menu, restoring focus to the toggle button.

Related patterns


For full implementation detail, examples, and testing notes, see references/pattern.md.

Pattern page: https://uxpatterns.dev/patterns/navigation/hambuger-menu

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

accordion

免费

Use when implementing expand and collapse content sections.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

Use when implementing user account configuration and preferences.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

Use when implementing social activity and updates stream.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

ai-chat

免费

Use when implementing conversational AI chat interfaces.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

Use when implementing handling AI-specific errors.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

Use when implementing loading states for AI operations.

中文简介正在准备中。当前显示原文说明。

thedaviddias/ux-patterns-for-developers2662026年10月5日 更新

查看 thedaviddias 的全部技能

报告此技能的问题