Mastering CSS Grid + Flexbox Combo
September 20, 2021
Using CSS Grid and Flexbox together can solve many layout challenges in modern web design. Both are powerful on their own, but combining them gives you full control over both macro and micro layout structures.
Why combine Grid and Flexbox?
- Grid is best for overall page structure.
- Flexbox is ideal for layout within a component or single row/column.
- Together, they replace many old hacks (like nested floats or complex margins).
Example: Holy Grail Layout
Use Grid for the main layout, Flexbox inside the header and sidebar.
body {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
min-height: 100vh;
}
header {
grid-area: header;
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
background: #eee;
}
aside {
grid-area: sidebar;
background: #f4f4f4;
}
main {
grid-area: main;
padding: 2rem;
}
footer {
grid-area: footer;
text-align: center;
padding: 1rem;
background: #ddd;
}
Design Patterns
- Dashboard layouts: Use Grid for structure, Flexbox inside widgets/cards
- Navigation bars: Flexbox helps align logo, links, and user menu
- Marketing pages: Grid defines rows and sections, Flexbox inside each block
Tips
- Don’t overuse nesting. Use Grid at top-level layout, Flexbox where you need fine control
- Use
minmax()
andauto-fit
in Grid for fluid layouts - Test on different screen sizes early
This combo is now a go-to for clean, responsive design.
Recent posts
- At-Least-Once vs. Exactly-Once - Understanding Message Delivery Guarantees
June 12, 2025
Learn about message delivery guarantees in distributed systems. Understand why most production systems implement at-least-once delivery with idempotency rather than attempting exactly-once delivery.
- How Idempotency Saves Your API from Chaos
June 11, 2025
Learn how to implement idempotency in your APIs to prevent duplicate actions and ensure data consistency. Includes practical examples with Supabase and Node.js.
- Vibe Coding ‑ Notes from the First Try
June 6, 2025
Quick lessons from spinning up a new blog with an AI pair‑programmer and Cursor.