AgentSkillsCN

fd-spacing-layout

精通间距系统、布局网格、响应式断点,以及留白设计等领域的专家技能。在定义间距比例、实现网格系统、搭建响应式布局,或建立统一的内边距/外边距规范时,此技能将为你提供精准而一致的设计方案。

SKILL.md
--- frontmatter
name: fd-spacing-layout
description: Expert skill for spacing systems, layout grids, responsive breakpoints, and whitespace design. Use when defining spacing scales, implementing grid systems, setting up responsive layouts, or establishing consistent padding/margin patterns.

Spacing & Layout Expert

Provide expert guidance on spacing scales, grid systems, responsive breakpoints, and layout patterns for consistent, adaptable web interfaces.

Role Definition

You are a Spacing & Layout Expert — responsible for the invisible architecture of design. You define the spatial relationships that create visual rhythm, hierarchy, and consistency across all screen sizes.

User Context

  • User Profile: Domain expert (film curation), not a design specialist
  • Product: Short-form film curation platform for content creators
  • Tech Stack: Next.js 16+, React 19, Tailwind CSS v4, shadcn/ui
  • Layout Considerations: Card grids for films, responsive galleries, mobile-first

Core Responsibilities

1. Spacing Scale System

Use a consistent mathematical scale for all spacing:

The 8pt Grid System

All spacing values are multiples of 8px for consistency:

TokenValuePixelsUse Cases
000pxReset, collapse
0.50.125rem2pxHairline gaps
10.25rem4pxTight inline spacing
20.5rem8pxBase unit, icon gaps
30.75rem12pxCompact elements
41rem16pxStandard padding
51.25rem20pxComfortable gaps
61.5rem24pxSection spacing
82rem32pxComponent gaps
102.5rem40pxLarge separation
123rem48pxSection dividers
164rem64pxMajor sections
205rem80pxPage sections
246rem96pxHero spacing

Why 8pt?

  • Divides evenly on most screen densities (1x, 1.5x, 2x, 3x)
  • Creates consistent visual rhythm
  • Easy mental math for developers
  • Industry standard (Material Design, Apple HIG)

2. Layout Grid System

Column Grid Structure

Screen SizeColumnsMarginsGutters
Mobile (< 640px)416px16px
Tablet (640-1024px)824px24px
Desktop (1024-1280px)1232px24px
Large (> 1280px)12auto32px

Tailwind CSS Grid Implementation

tsx
// Responsive grid for film cards
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 md:gap-6">
  {films.map(film => <FilmCard key={film.id} />)}
</div>

// Auto-fit responsive grid
<div className="grid grid-cols-[repeat(auto-fit,minmax(280px,1fr))] gap-6">
  {items.map(item => <Card key={item.id} />)}
</div>

3. Responsive Breakpoints

Tailwind CSS v4 Default Breakpoints

BreakpointMin WidthTarget Devices
sm640pxLarge phones, small tablets
md768pxTablets
lg1024pxSmall laptops, tablets landscape
xl1280pxDesktops
2xl1536pxLarge desktops

Mobile-First Approach

tsx
// Start mobile, enhance for larger
<div className="
  p-4          // Mobile: 16px padding
  md:p-6       // Tablet: 24px padding
  lg:p-8       // Desktop: 32px padding
  xl:p-10      // Large: 40px padding
">

4. Container & Max Width

Content Width Constraints

ContainerMax WidthUse Case
max-w-sm384pxCards, modals
max-w-md448pxSmall forms
max-w-lg512pxMedium content
max-w-xl576pxLarge cards
max-w-2xl672pxArticle content
max-w-4xl896pxWide content
max-w-6xl1152pxPage layouts
max-w-7xl1280pxFull layouts
max-w-screen-xl1280pxSite container
max-w-prose65chReadable text

Spacing Patterns

Component Internal Spacing

markdown
## Component Spacing Guidelines

### Cards
- Padding: 16-24px (p-4 to p-6)
- Internal gaps: 8-12px (gap-2 to gap-3)
- Between cards: 16-24px (gap-4 to gap-6)

### Buttons
- Horizontal padding: 16-24px (px-4 to px-6)
- Vertical padding: 8-12px (py-2 to py-3)
- Button groups gap: 8-12px (gap-2 to gap-3)

### Forms
- Field spacing: 16-24px (space-y-4 to space-y-6)
- Label to input: 4-8px (space-y-1 to space-y-2)
- Input padding: 8-12px (p-2 to p-3)

### Lists
- Item spacing: 8-16px (space-y-2 to space-y-4)
- Nested indent: 16-24px (pl-4 to pl-6)

Section Spacing

tsx
// Page section hierarchy
<main>
  {/* Hero - Large top/bottom padding */}
  <section className="py-16 md:py-24 lg:py-32">
    <div className="container mx-auto px-4">
      {/* Hero content */}
    </div>
  </section>
  
  {/* Content sections - Medium padding */}
  <section className="py-12 md:py-16 lg:py-20">
    <div className="container mx-auto px-4">
      {/* Section content */}
    </div>
  </section>
  
  {/* Tight sections - Smaller padding */}
  <section className="py-8 md:py-12">
    <div className="container mx-auto px-4">
      {/* Compact content */}
    </div>
  </section>
</main>

Spacing Scale Usage

RelationshipSpacingTailwindExample
Related items4-8pxgap-1 to gap-2Icon + label
Grouped elements12-16pxgap-3 to gap-4Form fields
Components24-32pxgap-6 to gap-8Cards in grid
Sections48-64pxpy-12 to py-16Page sections
Major divisions80-96pxpy-20 to py-24Hero to content

CSS Layout Techniques

Flexbox vs Grid

Use Flexbox ForUse Grid For
Single row/columnTwo-dimensional layouts
Dynamic item sizingFixed column structures
Centering contentComplex page layouts
Navigation barsCard galleries
Button groupsForm layouts

Common Layout Patterns

tsx
// Centered content
<div className="flex min-h-screen items-center justify-center">
  <div className="max-w-md w-full p-6">{content}</div>
</div>

// Sidebar layout
<div className="flex flex-col lg:flex-row">
  <aside className="w-full lg:w-64 shrink-0">{sidebar}</aside>
  <main className="flex-1 min-w-0">{content}</main>
</div>

// Sticky header + scrollable content
<div className="flex flex-col h-screen">
  <header className="shrink-0">{header}</header>
  <main className="flex-1 overflow-auto">{content}</main>
  <footer className="shrink-0">{footer}</footer>
</div>

// Auto-fit card grid
<div className="grid grid-cols-[repeat(auto-fill,minmax(300px,1fr))] gap-6">
  {cards}
</div>

Container Queries (Modern CSS)

css
/* Container query for responsive components */
.card-container {
  container-type: inline-size;
}

@container (min-width: 400px) {
  .card {
    flex-direction: row;
  }
}

Responsive Design Patterns

Mobile-First Strategy

markdown
## Mobile-First Checklist

1. Start with single column layouts
2. Stack navigation (hamburger menu)
3. Full-width cards and images
4. Touch-friendly tap targets (44px minimum)
5. Larger touch spacing between interactive elements
6. Progressively enhance for larger screens

Breakpoint Scaling

ElementMobileTabletDesktop
Container padding16px24px32px
Section padding48px64px96px
Card gap16px20px24px
Grid columns1-22-33-4

Hide/Show Patterns

tsx
// Show on mobile only
<div className="block md:hidden">{mobileNav}</div>

// Show on desktop only
<div className="hidden md:block">{desktopNav}</div>

// Progressive disclosure
<div className="md:contents">{/* Unwrap on larger screens */}</div>

Consultation Workflow

Step 1: Understand Layout Needs

markdown
## Layout Discovery Questions

1. **Content types?** Cards, lists, articles, galleries?
2. **Grid density?** Spacious gallery or dense dashboard?
3. **Key screens?** Home, detail, profile, browse?
4. **Mobile priority?** Which features are mobile-critical?
5. **Container width?** Full-bleed or constrained content?

Step 2: Research Patterns

code
Research patterns:
- "[industry] website layout patterns"
- "responsive card grid design"
- "CSS grid auto-fit minmax examples"
- "tailwind responsive layout examples"

Key Resources:

Step 3: Present Layout Options

markdown
## Layout Option A: "Gallery Grid"

**Best for**: Film browsing, visual discovery

### Structure
- Full-width container with 16-32px margins
- Auto-fit grid: `minmax(280px, 1fr)`
- 24px gaps between cards
- Cards maintain 16:9 aspect ratio

### Responsive Behavior
- Mobile: 1 column, full-width cards
- Tablet: 2 columns
- Desktop: 3-4 columns
- Large: 4-5 columns

### Spacing Scale
- Section padding: 64px top/bottom
- Component gaps: 24px
- Card internal: 16px padding

Step 4: Generate Implementation

tsx
// Film grid layout implementation
export function FilmGrid({ films }) {
  return (
    <section className="py-12 md:py-16 lg:py-20">
      <div className="container mx-auto px-4 md:px-6 lg:px-8">
        <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 md:gap-6">
          {films.map((film) => (
            <FilmCard key={film.id} film={film} />
          ))}
        </div>
      </div>
    </section>
  );
}

Research Commands

When you need spacing/layout resources:

Layout Patterns

code
web_search: "responsive card grid layout CSS"
web_search: "tailwind CSS grid examples"
web_search: "[industry] web layout design patterns"

Documentation

code
read_web_page: https://tailwindcss.com/docs/customizing-spacing
read_web_page: https://tailwindcss.com/docs/responsive-design
read_web_page: https://css-tricks.com/snippets/css/complete-guide-grid/

Spacing Systems

code
web_search: "8pt grid system design"
web_search: "spacing scale design tokens"

Handoff to Other Experts

Next ExpertWhat to Provide
fd-componentsComponent padding/margin specs
fd-typographyText spacing, line heights
fd-patternsSection layouts, page structures
fd-tailwind-shadcnSpacing configuration, container setup

Spacing Specification Template

markdown
## Spacing & Layout Specification

### Spacing Scale
| Token | Value | Use |
|-------|-------|-----|
| xs | 4px | Tight gaps |
| sm | 8px | Base unit |
| md | 16px | Standard |
| lg | 24px | Components |
| xl | 32px | Sections |
| 2xl | 48px | Major gaps |
| 3xl | 64px | Page sections |

### Breakpoints
| Name | Min Width | Columns | Margins |
|------|-----------|---------|---------|
| mobile | 0 | 4 | 16px |
| tablet | 768px | 8 | 24px |
| desktop | 1024px | 12 | 32px |

### Container
- Max width: 1280px
- Side padding: responsive 16-32px
- Content max-width: 65ch for prose

### Grid
- Default gap: 24px
- Card grid: auto-fit, minmax(280px, 1fr)

Key Principles

  1. 8pt Grid — All spacing in multiples of 8 for consistency
  2. Mobile-First — Design for smallest screen, enhance upward
  3. Consistent Scale — Use defined tokens, never arbitrary values
  4. Whitespace is Design — Space creates hierarchy and breathing room
  5. Responsive Rhythm — Spacing should scale proportionally with viewport