--- name: responsive-layout-builder description: Build responsive layouts with CSS Grid, Flexbox, and container queries. Use when creating responsive designs, fixing layout issues, or building mobile-first layouts. --- # Responsive Layout Builder ## Instructions When building responsive layouts: 1. **Identify the layout pattern** (grid, sidebar, cards, etc.) 2. **Start mobile-first** 3. **Use appropriate CSS technique** (Grid vs Flexbox) 4. **Add breakpoints** for larger screens 5. **Test across viewports** ## Breakpoints ```css /* Tailwind defaults */ sm: 640px /* Small devices */ md: 768px /* Tablets */ lg: 1024px /* Laptops */ xl: 1280px /* Desktops */ 2xl: 1536px /* Large screens */ /* Custom CSS */ @media (min-width: 640px) { } @media (min-width: 768px) { } @media (min-width: 1024px) { } ``` ## Common Layout Patterns ### 1. Holy Grail Layout ```tsx // Tailwind CSS
Header
Main Content
``` ```css /* Plain CSS */ .layout { display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: 1fr; min-height: 100vh; } @media (min-width: 768px) { .layout { grid-template-columns: 250px 1fr; } .header, .footer { grid-column: 1 / -1; } } ``` ### 2. Responsive Card Grid ```tsx // Tailwind - Auto-fit cards
{items.map(item => ( ))}
// Auto-fill with minimum width
{items.map(item => ( ))}
``` ```css /* Plain CSS */ .card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; } ``` ### 3. Sidebar Layout ```tsx // Fixed sidebar, scrollable content
Main Content
// Collapsible sidebar
...
``` ### 4. Hero Section ```tsx
{/* Background */}
{/* Content */}

Headline Here

Subheadline text goes here with more details.

``` ### 5. Masonry Grid ```tsx // CSS Columns approach
{items.map(item => (
))}
``` ### 6. Sticky Header ```tsx
``` ## Container Queries (Modern) ```css /* Define container */ .card-container { container-type: inline-size; } /* Query the container */ @container (min-width: 400px) { .card { display: flex; flex-direction: row; } } ``` ```tsx // Tailwind v3.2+
Content
``` ## Flexbox vs Grid Decision | Use Flexbox | Use Grid | |-------------|----------| | Navigation bars | Page layouts | | Card content alignment | Card grids | | Centering content | Complex 2D layouts | | Space distribution | Overlapping elements | | Unknown item count | Defined structure | ## Responsive Typography ```tsx // Fluid typography with clamp

Responsive Heading

// Tailwind responsive

Responsive Heading

``` ## Testing Checklist - [ ] 320px (small phones) - [ ] 375px (iPhone) - [ ] 768px (tablet portrait) - [ ] 1024px (tablet landscape / laptop) - [ ] 1280px+ (desktop) - [ ] Test with actual content (not lorem ipsum) - [ ] Test with long/short content variations