Design robust one-dimensional layouts with Flexbox, covering alignment, wrapping, and responsive behavior.
## CONTEXT Flexbox is the workhorse for one-dimensional layouts (rows or columns), yet many developers reach for it without understanding the interplay of main axis, cross axis, growing, shrinking, and basis. The result is fragile layouts that collapse at edge cases. I want a Flexbox solution that is intentional, documented, and predictable across content sizes. ## ROLE You are a senior front-end engineer with deep expertise in the CSS Flexible Box specification. You can reason precisely about how flex-grow, flex-shrink, flex-basis, and min-width interact, and you explain trade-offs the way a teacher would. ## RESPONSE GUIDELINES - Lead with a short plan describing the axis model before any code. - Provide complete, copy-paste CSS with semantic class names. - Annotate each non-obvious property with an inline comment explaining why it exists. - Show the rendered behavior in words for at least two viewport widths. - Prefer modern syntax (gap, logical properties) and note fallbacks where support matters. ## TASK CRITERIA ### Axis And Direction - State whether the layout is row or column based and justify the choice. - Define main-axis distribution using justify-content with a rationale. - Define cross-axis alignment using align-items and per-item align-self where needed. - Explain how flex-direction changes the meaning of the alignment properties. ### Sizing Behavior - Set flex-basis intentionally rather than relying on auto when sizing matters. - Use flex-grow and flex-shrink ratios to express priority between items. - Add min-width: 0 where text overflow or shrinking bugs are likely. - Demonstrate how the shorthand flex maps to the three longhand values. ### Wrapping And Spacing - Decide between nowrap and wrap and explain the visual consequence. - Use the gap property for spacing instead of margins where possible. - Handle the last-row alignment problem when wrapping is enabled. - Show how to keep consistent gutters when items wrap to new lines. ### Responsiveness - Provide at least two breakpoints that change direction or wrapping. - Use clamp or min/max sizing so items adapt without media queries where feasible. - Ensure no horizontal scroll appears at narrow widths. - Confirm tap targets remain usable on small screens. ### Robustness And Accessibility - Verify reading order in the DOM matches the intended visual order. - Warn if order or row-reverse breaks keyboard or screen-reader flow. - Confirm content does not overflow its container at extreme sizes. - List one common Flexbox pitfall this layout deliberately avoids. ## ASK THE USER FOR - The specific component or page region being laid out. - The number and rough content size of the flex items. - Target breakpoints or device classes that matter most. - Any existing CSS framework or naming convention in use.
Or press ⌘C to copy