ヘッダー 中級

メガメニュー

ナビ項目にホバー/フォーカスすると、複数カラムのリンクと説明を一度に見せる大型ドロップダウン。情報量の多いECやサービスサイトの回遊性を高めます。focus-within とJSの自動デモ開閉で動きを確認できます。

#header#mega-menu#dropdown#navigation

ライブデモ

使用例(お題: アイドルグループ Sakura)

この技法を「アイドルグループ Sakura」というテーマのダミーサイトで実際に使った例です。

HTML
<!-- Sakura:公式グッズ通販のメガメニュー -->
<div class="hmm-frame">
  <header class="hmm-head">
    <a class="hmm-logo" href="#" onclick="return false">Sakura STORE</a>
    <nav class="hmm-nav">
      <div class="hmm-item" id="hmmItem">
        <button class="hmm-trigger" type="button" aria-expanded="false">グッズ <span class="hmm-caret">▾</span></button>
        <div class="hmm-mega" role="menu">
          <div class="hmm-col">
            <p class="hmm-col__head">ライブ</p>
            <a href="#" onclick="return false"><b>ペンライト</b><span>最新ツアー対応</span></a>
            <a href="#" onclick="return false"><b>Tシャツ</b><span>会場限定カラー</span></a>
            <a href="#" onclick="return false"><b>タオル</b><span>マフラータオル</span></a>
          </div>
          <div class="hmm-col">
            <p class="hmm-col__head">フォト</p>
            <a href="#" onclick="return false"><b>生写真</b><span>ランダム5枚</span></a>
            <a href="#" onclick="return false"><b>フォトブック</b><span>オフショット集</span></a>
            <a href="#" onclick="return false"><b>カレンダー</b><span>2026年版</span></a>
          </div>
          <div class="hmm-col hmm-col--promo">
            <p class="hmm-promo__tag">NEW</p>
            <p class="hmm-promo__title">2nd写真集</p>
            <p class="hmm-promo__text">予約受付スタート。</p>
            <span class="hmm-promo__btn">予約する →</span>
          </div>
        </div>
      </div>
      <a class="hmm-link" href="#" onclick="return false">チケット</a>
      <a class="hmm-link" href="#" onclick="return false">メンバー</a>
      <a class="hmm-link" href="#" onclick="return false">ニュース</a>
    </nav>
    <button class="hmm-cta" type="button">マイページ</button>
  </header>

  <div class="hmm-stage">
    <p class="hmm-hint">「グッズ」にホバー/フォーカスでメガメニューが開きます<br><small>(自動で開閉も実演します)</small></p>
  </div>
</div>
CSS
/* Sakura(アイドル通販):メガメニューの再スキン */
* { box-sizing: border-box; }
body { margin: 0; font-family: "Hiragino Kaku Gothic ProN", "Segoe UI", system-ui, sans-serif; }

.hmm-frame { position: relative; width: 100%; height: 380px; overflow: hidden; background: #fff0f6; }

.hmm-head { position: relative; z-index: 20; display: flex; align-items: center; gap: 22px; height: 60px; padding: 0 24px; background: #fff; border-bottom: 1px solid #ffd9e8; }
.hmm-logo { font-size: 19px; font-weight: 800; color: #d6336c; text-decoration: none; letter-spacing: .02em; }
.hmm-nav { display: flex; align-items: center; gap: 6px; }
.hmm-trigger, .hmm-link { font: inherit; font-size: 13.5px; font-weight: 600; color: #6a3050; background: none; border: none; cursor: pointer; text-decoration: none; padding: 8px 12px; border-radius: 8px; display: inline-flex; align-items: center; gap: 5px; transition: background .2s ease, color .2s ease; }
.hmm-trigger:hover, .hmm-link:hover { background: #ffe3ee; color: #d6336c; }
.hmm-caret { font-size: 10px; transition: transform .25s ease; }
.hmm-cta { font: inherit; font-size: 13px; font-weight: 700; color: #fff; cursor: pointer; margin-left: auto; border: none; padding: 9px 18px; border-radius: 999px; background: linear-gradient(135deg,#f06595,#d6336c); transition: filter .15s ease, transform .15s ease; }
.hmm-cta:hover { filter: brightness(1.06); transform: translateY(-1px); }

.hmm-item { position: static; }
.hmm-mega {
  position: absolute; top: 60px; left: 16px; right: 16px;
  display: grid; grid-template-columns: 1fr 1fr 1.1fr; gap: 10px;
  padding: 18px; border-radius: 14px; background: #fff;
  box-shadow: 0 24px 50px rgba(214,51,108,.2); border: 1px solid #ffe0ec;
  opacity: 0; transform: translateY(-8px); pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.hmm-item:hover .hmm-mega, .hmm-item:focus-within .hmm-mega, .hmm-item.is-open .hmm-mega { opacity: 1; transform: translateY(0); pointer-events: auto; }
.hmm-item:hover .hmm-caret, .hmm-item.is-open .hmm-caret { transform: rotate(180deg); }

.hmm-col__head { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .1em; color: #c98aa8; text-transform: uppercase; }
.hmm-col a { display: block; text-decoration: none; padding: 8px 10px; border-radius: 9px; transition: background .18s ease; }
.hmm-col a:hover { background: #fff0f6; }
.hmm-col a b { display: block; font-size: 13.5px; color: #5a2440; }
.hmm-col a span { font-size: 11.5px; color: #b07d96; }

.hmm-col--promo { background: linear-gradient(150deg, #f06595, #cc5de8); color: #fff; border-radius: 11px; padding: 16px; display: flex; flex-direction: column; justify-content: center; }
.hmm-promo__tag { align-self: flex-start; font-size: 10px; font-weight: 700; letter-spacing: .12em; background: rgba(255,255,255,.24); padding: 3px 9px; border-radius: 999px; margin: 0 0 8px; }
.hmm-promo__title { margin: 0; font-size: 18px; font-weight: 800; }
.hmm-promo__text { margin: 5px 0 12px; font-size: 12px; opacity: .92; }
.hmm-promo__btn { font-size: 12.5px; font-weight: 700; }

.hmm-stage { display: grid; place-content: center; height: calc(100% - 60px); text-align: center; }
.hmm-hint { color: #a86a86; font-size: 14px; line-height: 1.8; }
.hmm-hint small { color: #c99cb0; }

@media (prefers-reduced-motion: reduce) { .hmm-mega, .hmm-caret, .hmm-cta { transition: none; } }
JavaScript
// (デモと同じフックを流用)ホバー/フォーカス+自動開閉でメガメニューを実演
(() => {
  const item = document.getElementById('hmmItem');
  if (!item) return;
  const trigger = item.querySelector('.hmm-trigger');
  const sync = () => trigger && trigger.setAttribute('aria-expanded', item.classList.contains('is-open') ? 'true' : 'false');
  let auto = !matchMedia('(prefers-reduced-motion: reduce)').matches;
  ['pointerenter', 'focusin', 'pointerdown'].forEach(ev => item.addEventListener(ev, () => { auto = false; item.classList.remove('is-open'); sync(); }));
  if (auto) {
    let open = false;
    const tick = () => { if (!auto) return; open = !open; item.classList.toggle('is-open', open); sync(); setTimeout(tick, open ? 2200 : 1400); };
    setTimeout(tick, 1000);
  }
})();

実装ガイド

使いどころ

EC・サービス・メディアなどリンク数が多いサイトで、カテゴリを一望させたいヘッダーに。親項目にホバー/フォーカスすると、複数カラムのリンクと説明、プロモ枠を一度に開きます。

実装時の注意点

開閉は CSS の :hover と :focus-within で行い、JS は「プレビューで動きが見えるよう自動で開閉する」補助のみ。実ユーザーの操作が来たら自動デモは止まります。パネルはヘッダー幅いっぱいに広げるため、項目側を position:static にして絶対配置パネルの基準をフレームに委ねています。

対応ブラウザ

:focus-within・grid・transition は全モダンブラウザで対応します。キーボード操作にも対応しますが、実運用では Esc で閉じる・aria 属性の同期(aria-expanded)を補うとよりアクセシブルです。

よくある失敗

ホバーだけで開くとタッチ端末で使えないため、クリック/タップでも開くフォールバックを足してください。パネルが画面端で切れないよう、左右に余白を持たせること。開閉に遅延(hover intent)が無いと、マウスが横切っただけで開いて煩わしくなります。

応用例

カラム数をブレークポイントで可変にする、プロモ枠に画像やバナーを差し込む、選択中カテゴリをハイライトする、メニュー項目ごとに色を変えるなどの拡張ができます。

コード

HTML
<!-- ホバー/フォーカスで開く多カラムのメガメニュー -->
<div class="hmm-frame">
  <header class="hmm-head">
    <a class="hmm-logo" href="#" onclick="return false">Mercato</a>
    <nav class="hmm-nav">
      <div class="hmm-item" id="hmmItem">
        <button class="hmm-trigger" type="button" aria-expanded="false">製品 <span class="hmm-caret">▾</span></button>
        <!-- メガパネル本体 -->
        <div class="hmm-mega" role="menu">
          <div class="hmm-col">
            <p class="hmm-col__head">デザイン</p>
            <a href="#" onclick="return false"><b>エディタ</b><span>直感的な編集環境</span></a>
            <a href="#" onclick="return false"><b>テンプレート</b><span>200種のひな形</span></a>
            <a href="#" onclick="return false"><b>素材ライブラリ</b><span>写真・アイコン</span></a>
          </div>
          <div class="hmm-col">
            <p class="hmm-col__head">運用</p>
            <a href="#" onclick="return false"><b>公開ホスティング</b><span>独自ドメイン対応</span></a>
            <a href="#" onclick="return false"><b>アクセス解析</b><span>流入を可視化</span></a>
            <a href="#" onclick="return false"><b>フォーム</b><span>問い合わせ収集</span></a>
          </div>
          <div class="hmm-col hmm-col--promo">
            <p class="hmm-promo__tag">NEW</p>
            <p class="hmm-promo__title">AIアシスト</p>
            <p class="hmm-promo__text">下書きから一気に1ページ。</p>
            <span class="hmm-promo__btn">詳しく →</span>
          </div>
        </div>
      </div>
      <a class="hmm-link" href="#" onclick="return false">料金</a>
      <a class="hmm-link" href="#" onclick="return false">事例</a>
      <a class="hmm-link" href="#" onclick="return false">サポート</a>
    </nav>
    <button class="hmm-cta" type="button">ログイン</button>
  </header>

  <div class="hmm-stage">
    <p class="hmm-hint">「製品」にホバー/フォーカスでメガメニューが開きます<br><small>(自動で開閉も実演します)</small></p>
  </div>
</div>
CSS
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; }

.hmm-frame { position: relative; width: 100%; height: 380px; overflow: hidden; background: #f4f5f9; }

.hmm-head {
  position: relative; z-index: 20;
  display: flex; align-items: center; gap: 22px;
  height: 60px; padding: 0 24px;
  background: #fff; border-bottom: 1px solid #ebedf3;
}
.hmm-logo { font-size: 19px; font-weight: 800; color: #111827; text-decoration: none; }
.hmm-nav { display: flex; align-items: center; gap: 6px; }

.hmm-trigger, .hmm-link {
  font: inherit; font-size: 13.5px; font-weight: 600; color: #374151;
  background: none; border: none; cursor: pointer; text-decoration: none;
  padding: 8px 12px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 5px;
  transition: background .2s ease, color .2s ease;
}
.hmm-trigger:hover, .hmm-link:hover { background: #eef1fb; color: #4f46e5; }
.hmm-caret { font-size: 10px; transition: transform .25s ease; }

.hmm-cta {
  font: inherit; font-size: 13px; font-weight: 700; color: #fff; cursor: pointer;
  margin-left: auto; border: none; padding: 9px 18px; border-radius: 999px;
  background: #4f46e5; transition: filter .15s ease, transform .15s ease;
}
.hmm-cta:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* メガパネル */
.hmm-item { position: static; }   /* パネルはヘッダー幅いっぱいに */
.hmm-mega {
  position: absolute;
  top: 60px; left: 16px; right: 16px;
  display: grid; grid-template-columns: 1fr 1fr 1.1fr; gap: 10px;
  padding: 18px; border-radius: 14px;
  background: #fff;
  box-shadow: 0 24px 50px rgba(20,24,50,.16);
  border: 1px solid #eef0f6;
  opacity: 0; transform: translateY(-8px); pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.hmm-item:hover .hmm-mega,
.hmm-item:focus-within .hmm-mega,
.hmm-item.is-open .hmm-mega {
  opacity: 1; transform: translateY(0); pointer-events: auto;
}
.hmm-item:hover .hmm-caret,
.hmm-item.is-open .hmm-caret { transform: rotate(180deg); }

.hmm-col__head { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .1em; color: #9aa1b1; text-transform: uppercase; }
.hmm-col a {
  display: block; text-decoration: none; padding: 8px 10px; border-radius: 9px;
  transition: background .18s ease;
}
.hmm-col a:hover { background: #f3f4fb; }
.hmm-col a b { display: block; font-size: 13.5px; color: #1f2433; }
.hmm-col a span { font-size: 11.5px; color: #8b91a1; }

.hmm-col--promo {
  background: linear-gradient(150deg, #6366f1, #a855f7);
  color: #fff; border-radius: 11px; padding: 16px;
  display: flex; flex-direction: column; justify-content: center;
}
.hmm-promo__tag { align-self: flex-start; font-size: 10px; font-weight: 700; letter-spacing: .12em; background: rgba(255,255,255,.22); padding: 3px 9px; border-radius: 999px; margin: 0 0 8px; }
.hmm-promo__title { margin: 0; font-size: 18px; font-weight: 800; }
.hmm-promo__text { margin: 5px 0 12px; font-size: 12px; opacity: .92; }
.hmm-promo__btn { font-size: 12.5px; font-weight: 700; }

.hmm-stage { display: grid; place-content: center; height: calc(100% - 60px); text-align: center; }
.hmm-hint { color: #6b7180; font-size: 14px; line-height: 1.8; }
.hmm-hint small { color: #a2a8b6; }

@media (prefers-reduced-motion: reduce) {
  .hmm-mega, .hmm-caret, .hmm-cta { transition: none; }
}
JavaScript
// ホバー/フォーカスに加え、プレビューで動きが見えるよう自動で開閉も実演
(() => {
  const item = document.getElementById('hmmItem');
  if (!item) return;

  const trigger = item.querySelector('.hmm-trigger');
  const sync = () => trigger && trigger.setAttribute('aria-expanded', item.classList.contains('is-open') ? 'true' : 'false');

  // 実ユーザー操作が来たら自動デモは止める
  let auto = !matchMedia('(prefers-reduced-motion: reduce)').matches;
  ['pointerenter', 'focusin', 'pointerdown'].forEach(ev =>
    item.addEventListener(ev, () => { auto = false; item.classList.remove('is-open'); sync(); }));

  if (auto) {
    let open = false;
    const tick = () => {
      if (!auto) return;
      open = !open;
      item.classList.toggle('is-open', open);
      sync();
      setTimeout(tick, open ? 2200 : 1400);
    };
    setTimeout(tick, 1000);
  }
})();

🤖 AIエージェント用プロンプト

このままコピーしてAIに貼り付け「追加する場所」だけ書き換えればOK
あなたは熟練のフロントエンドエンジニアです。私のWebサイトに「メガメニュー」の効果を追加してください。

# 追加してほしい効果
メガメニュー(ヘッダー)
ナビ項目にホバー/フォーカスすると、複数カラムのリンクと説明を一度に見せる大型ドロップダウン。情報量の多いECやサービスサイトの回遊性を高めます。focus-within とJSの自動デモ開閉で動きを確認できます。

# 追加する場所
👉【ここに対象箇所を記入:例「トップのヒーローセクション」「お問い合わせボタン」「記事カードの一覧」など】

# 参考実装(この見た目・挙動を再現してください)
【HTML】
<!-- ホバー/フォーカスで開く多カラムのメガメニュー -->
<div class="hmm-frame">
  <header class="hmm-head">
    <a class="hmm-logo" href="#" onclick="return false">Mercato</a>
    <nav class="hmm-nav">
      <div class="hmm-item" id="hmmItem">
        <button class="hmm-trigger" type="button" aria-expanded="false">製品 <span class="hmm-caret">▾</span></button>
        <!-- メガパネル本体 -->
        <div class="hmm-mega" role="menu">
          <div class="hmm-col">
            <p class="hmm-col__head">デザイン</p>
            <a href="#" onclick="return false"><b>エディタ</b><span>直感的な編集環境</span></a>
            <a href="#" onclick="return false"><b>テンプレート</b><span>200種のひな形</span></a>
            <a href="#" onclick="return false"><b>素材ライブラリ</b><span>写真・アイコン</span></a>
          </div>
          <div class="hmm-col">
            <p class="hmm-col__head">運用</p>
            <a href="#" onclick="return false"><b>公開ホスティング</b><span>独自ドメイン対応</span></a>
            <a href="#" onclick="return false"><b>アクセス解析</b><span>流入を可視化</span></a>
            <a href="#" onclick="return false"><b>フォーム</b><span>問い合わせ収集</span></a>
          </div>
          <div class="hmm-col hmm-col--promo">
            <p class="hmm-promo__tag">NEW</p>
            <p class="hmm-promo__title">AIアシスト</p>
            <p class="hmm-promo__text">下書きから一気に1ページ。</p>
            <span class="hmm-promo__btn">詳しく →</span>
          </div>
        </div>
      </div>
      <a class="hmm-link" href="#" onclick="return false">料金</a>
      <a class="hmm-link" href="#" onclick="return false">事例</a>
      <a class="hmm-link" href="#" onclick="return false">サポート</a>
    </nav>
    <button class="hmm-cta" type="button">ログイン</button>
  </header>

  <div class="hmm-stage">
    <p class="hmm-hint">「製品」にホバー/フォーカスでメガメニューが開きます<br><small>(自動で開閉も実演します)</small></p>
  </div>
</div>

【CSS】
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; }

.hmm-frame { position: relative; width: 100%; height: 380px; overflow: hidden; background: #f4f5f9; }

.hmm-head {
  position: relative; z-index: 20;
  display: flex; align-items: center; gap: 22px;
  height: 60px; padding: 0 24px;
  background: #fff; border-bottom: 1px solid #ebedf3;
}
.hmm-logo { font-size: 19px; font-weight: 800; color: #111827; text-decoration: none; }
.hmm-nav { display: flex; align-items: center; gap: 6px; }

.hmm-trigger, .hmm-link {
  font: inherit; font-size: 13.5px; font-weight: 600; color: #374151;
  background: none; border: none; cursor: pointer; text-decoration: none;
  padding: 8px 12px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 5px;
  transition: background .2s ease, color .2s ease;
}
.hmm-trigger:hover, .hmm-link:hover { background: #eef1fb; color: #4f46e5; }
.hmm-caret { font-size: 10px; transition: transform .25s ease; }

.hmm-cta {
  font: inherit; font-size: 13px; font-weight: 700; color: #fff; cursor: pointer;
  margin-left: auto; border: none; padding: 9px 18px; border-radius: 999px;
  background: #4f46e5; transition: filter .15s ease, transform .15s ease;
}
.hmm-cta:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* メガパネル */
.hmm-item { position: static; }   /* パネルはヘッダー幅いっぱいに */
.hmm-mega {
  position: absolute;
  top: 60px; left: 16px; right: 16px;
  display: grid; grid-template-columns: 1fr 1fr 1.1fr; gap: 10px;
  padding: 18px; border-radius: 14px;
  background: #fff;
  box-shadow: 0 24px 50px rgba(20,24,50,.16);
  border: 1px solid #eef0f6;
  opacity: 0; transform: translateY(-8px); pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.hmm-item:hover .hmm-mega,
.hmm-item:focus-within .hmm-mega,
.hmm-item.is-open .hmm-mega {
  opacity: 1; transform: translateY(0); pointer-events: auto;
}
.hmm-item:hover .hmm-caret,
.hmm-item.is-open .hmm-caret { transform: rotate(180deg); }

.hmm-col__head { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .1em; color: #9aa1b1; text-transform: uppercase; }
.hmm-col a {
  display: block; text-decoration: none; padding: 8px 10px; border-radius: 9px;
  transition: background .18s ease;
}
.hmm-col a:hover { background: #f3f4fb; }
.hmm-col a b { display: block; font-size: 13.5px; color: #1f2433; }
.hmm-col a span { font-size: 11.5px; color: #8b91a1; }

.hmm-col--promo {
  background: linear-gradient(150deg, #6366f1, #a855f7);
  color: #fff; border-radius: 11px; padding: 16px;
  display: flex; flex-direction: column; justify-content: center;
}
.hmm-promo__tag { align-self: flex-start; font-size: 10px; font-weight: 700; letter-spacing: .12em; background: rgba(255,255,255,.22); padding: 3px 9px; border-radius: 999px; margin: 0 0 8px; }
.hmm-promo__title { margin: 0; font-size: 18px; font-weight: 800; }
.hmm-promo__text { margin: 5px 0 12px; font-size: 12px; opacity: .92; }
.hmm-promo__btn { font-size: 12.5px; font-weight: 700; }

.hmm-stage { display: grid; place-content: center; height: calc(100% - 60px); text-align: center; }
.hmm-hint { color: #6b7180; font-size: 14px; line-height: 1.8; }
.hmm-hint small { color: #a2a8b6; }

@media (prefers-reduced-motion: reduce) {
  .hmm-mega, .hmm-caret, .hmm-cta { transition: none; }
}

【JavaScript】
// ホバー/フォーカスに加え、プレビューで動きが見えるよう自動で開閉も実演
(() => {
  const item = document.getElementById('hmmItem');
  if (!item) return;

  const trigger = item.querySelector('.hmm-trigger');
  const sync = () => trigger && trigger.setAttribute('aria-expanded', item.classList.contains('is-open') ? 'true' : 'false');

  // 実ユーザー操作が来たら自動デモは止める
  let auto = !matchMedia('(prefers-reduced-motion: reduce)').matches;
  ['pointerenter', 'focusin', 'pointerdown'].forEach(ev =>
    item.addEventListener(ev, () => { auto = false; item.classList.remove('is-open'); sync(); }));

  if (auto) {
    let open = false;
    const tick = () => {
      if (!auto) return;
      open = !open;
      item.classList.toggle('is-open', open);
      sync();
      setTimeout(tick, open ? 2200 : 1400);
    };
    setTimeout(tick, 1000);
  }
})();

# 外部ライブラリ
なし(追加ライブラリ不要)

# 守ってほしいこと
- 既存のHTML構造・レイアウト・デザインを壊さないこと。必要に応じてクラス名・色・サイズを私のサイトに合わせて調整してよい。
- クラス名やidが既存と衝突しないよう、必要なら接頭辞で名前空間を分けること。
- レスポンシブ対応と prefers-reduced-motion への配慮を入れること。
- 私のサイトのフレームワーク(React / Vue / 素のHTML など)に合わせて実装すること。不明な場合は素のHTML/CSS/JSで提示し、組み込み手順も説明すること。
- 変更後の確認手順も簡潔に教えてください。