Communitygithub.com

レスポンシブレイアウト

CSSグリッド、フレックスボックス、コンテナクエリ、流動的なサイズ設定を使用して、スマートフォンからワイドデスクトップまで対応するページレイアウトを構築します。カードグリッド、ベントーグリッド、分割セクション、固定サイドバー、折りたたみ可能なナビゲーションを含みます。「モバイルで崩れる」、レスポンシブグリッド、ベントーレイアウト、モバイルメニュー、横スクロールやオーバーフローの修正、マルチカラムセクションのレイアウトなどに使用します。

レスポンシブレイアウト とは?

このスキルは、CSSグリッド、フレックスボックス、コンテナクエリ、流動的なサイズ設定を用いて、あらゆる画面サイズに適応するレスポンシブレイアウトを構築するためのものです。モバイルファーストの原則に基づき、コンテンツが実際に崩れる箇所にのみブレークポイントを追加するアプローチを推奨し、デスクトップファーストで後から修正する手法によるモバイルバグを防ぎます。具体的なパターンとして、ブレークポイント不要のカードグリッド、テキストとメディアを分割するセクション、ベントーグリッド、固定サイドバー、ヘッダーとモバイルメニューの実装方法を提供します。また、コンポーネントレベルのレスポンシブ対応にはコンテナクエリを推奨し、横スクロールの原因特定と修正方法、タッチ操作やビューポートの詳細設定、推奨テスト幅についても解説しています。Claude Code, Cursor, CodexなどのAIエージェントが、ユーザーのレイアウト要件に応じて適切なCSSコードを生成・説明する際に役立ちます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/imperfec-t/webcraft/tree/main/skills/responsive-layout

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

レスポンシブレイアウト は何をしますか?

レイアウトは自動的に適応するように記述し、コンテンツが実際に崩れる箇所にのみブレークポイントを追加します。デスクトップファーストで構築し後から修正するレイアウトは、モバイルバグの主な原因です。

ベース

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img, video, svg { max-width: 100%; height: auto; display: block; }

.container { width: min(100% - 2 * var(--gutter, 1.25rem), var(--container, 76rem)); margin-inline: auto; }
section { padding-block: var(--section, clamp(4rem, 3rem + 6vw, 9rem)); }

パターン

ブレークポイント不要のカードグリッド

.grid { display: grid; gap: clamp(1rem, 2vw, 2rem);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }

min(100%, 18rem) は、コンテナが最小幅より狭い場合のオーバーフローを防ぎます。短い最終行を引き伸ばしたくない場合は、auto-fill を代わりに使用します。

分割セクション(テキストとメディア)

.split { display: grid; gap: clamp(2rem, 5vw, 5rem); align-items: center; }
@media (min-width: 62em) { .split { grid-template-columns: 1.1fr 0.9fr; }
  .split--flip > :first-child { order: 2; } }

モバイルでは、どちらを先に表示するかを意図的に決定します。通常はテキストが先ですが、画像がメッセージの核となる場合は逆も可です。

ベントーグリッド

.bento { display: grid; gap: 1rem; grid-template-columns: repeat(6, 1fr); grid-auto-rows: minmax(12rem, auto); }
.bento > .wide  { grid-column: span 4; }
.bento > .half  { grid-column: span 3; }
.bento > .third { grid-column: span 2; }
.bento > .tall  { grid-row: span 2; }
@media (max-width: 61.99em) { .bento { grid-template-columns: repeat(2, 1fr); }
  .bento > * { grid-column: span 1; grid-row: auto; } .bento > .wide { grid-column: span 2; } }
@media (max-width: 35.99em) { .bento { grid-template-columns: 1fr; } .bento > * { grid-column: auto; } }

各行のスパンは列数に合計する必要があります。そうしないと隙間が生じます。クラスを書く前に、行のスケッチを描いてください。

長いコンテンツ(FAQ、記事)の横にある固定サイドバー

.with-aside { display: grid; gap: 3rem; }
@media (min-width: 62em) { .with-aside { grid-template-columns: 22rem 1fr; align-items: start; }
  .with-aside aside { position: sticky; top: 6rem; } }

position: sticky は、祖先要素に overflow: hidden または auto があると静かに失敗します。祖先要素では代わりに overflow: clip を使用してください。

ヘッダーとモバイルメニュー

  • デスクトップ: ロゴ、インラインナビゲーション、CTA。ナビゲーションが収まらなくなった時点でメニューボタンに折りたたみます。任意の幅で折りたたむのではありません。
  • メニューボタンは実際の <button aria-expanded aria-controls> です。パネルは開いている間フォーカスをトラップし、Escapeキーで閉じ、ボタンにフォーカスを戻します。
  • 開いている間は背景スクロールをロックし(html に overflow: hidden)、スクロールバーの幅を考慮してレイアウトジャンプを防ぎます。
  • ドロップダウンはタッチデバイスではクリックで開きます。ホバーだけでは到達できません。

コンポーネントレベルのレスポンシブ対応

カードがワイドグリッドと狭いサイドバーの両方に表示される場合、コンテナクエリを使用してカードが自身の幅に応答するようにします:

.card-wrap { container-type: inline-size; }
@container (min-width: 28rem) { .card { display: grid; grid-template-columns: 10rem 1fr; } }

ブレークポイント

ユーザーのズーム設定を尊重するため em を使用します。推奨セット: 36em (576px), 48em (768px), 62em (992px), 75em (1200px)。これがないと何が崩れるかを名前で説明できる場合にのみ追加します。

オーバーフロー調査

モバイルでの横スクロールは、ほとんどの場合以下のいずれかが原因です:

  1. 要素や画像に width がpxで固定されている。
  2. パディングのある親要素の中にある 100vw(代わりに 100% を使用)。
  3. URLやメールアドレスなどの長い改行されないテキスト:overflow-wrap: anywhere。
  4. 縮まないフレックス子要素:min-width: 0 を追加。
  5. 320px画面での minmax(20rem, 1fr) のグリッドトラック:最小値を min(100%, …) でラップ。
  6. ビューポート外の絶対配置された装飾:overflow: clip でセクションをクリップ。
  7. 全幅行の負のマージン。

原因を特定するには、コンソールで以下を実行します:

[...document.querySelectorAll("*")].filter(e => e.getBoundingClientRect().right > innerWidth + 1)

タッチとビューポートの詳細

  • タップターゲットは最低44x44px、間隔は8px以上。
  • 全高セクションには vh の代わりに svh/dvh を使用。モバイルブラウザのバーでコンテンツが切れるのを防ぎます。
  • 入力要素のフォントサイズは16px以上。それより小さいとiOSでフォーカス時にズームされます。
  • ノッチに対応: padding-inline: max(var(--gutter), env(safe-area-inset-left))。

テスト幅

320, 390, 768, 1024, 1440, 1920。また、ブラウザズーム200%と、ナビゲーションに長い翻訳文字列を入れた状態でもテストします。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

hero-section

Design and build the hero (first screen) of a website, including headline layout, media treatment, CTA, proof badge, marquee and entrance animation. Use this whenever someone asks for a hero section, a landing page header, "the top of my homepage", a cinematic or animated intro, a video background, a text marquee, or says their first screen looks plain or generic.

homepage-blueprint

Plan the section structure and content slots of a homepage for an agency, freelancer, studio or service business before any design or code. Use this whenever someone asks "what sections should my homepage have", "plan my website", "structure a landing page for my business", wants a wireframe or sitemap for a service site, or starts building a homepage without a clear outline.

scroll-motion

Add scroll-driven and entrance animation to a website with GSAP, ScrollTrigger and Lenis, including reveals, parallax, pinned sections, horizontal scroll, line drawing, counters and preloaders. Use this whenever someone wants a site to "feel premium", asks for smooth scrolling, scroll animations, parallax, text reveals, a pinned or sticky scroll section, an animated preloader, or names GSAP, ScrollTrigger, Lenis, Locomotive or AOS.

website-workflow

Plan and sequence a whole website build, from structure through design, code, WordPress and launch, by routing each stage to the right webcraft skill. Use this when someone asks to "build me a website", "design my site from scratch", "redo our homepage", wants an end-to-end plan for a marketing, agency, studio or service site, or the request spans more than one of structure, look, layout, motion, CMS and QA.

関連スキル