Multi-Row Header
What you'll learn: How to stack a logo, navigation, and search bar vertically using flexbox to create complex, organized headers.
The Core Idea
Many modern websites have headers with multiple horizontal sections stacked on top of each other—think of a logo row at the top, a navigation menu in the middle, and a search or action bar at the bottom. Using flexbox with flex-direction: column, you can easily organize these distinct rows while maintaining full control over alignment and spacing.
How It Works
You create a header container and set it to display: flex with flex-direction: column. This stacks your child elements (logo section, nav section, search section) vertically as separate rows. Each row can itself be a flex container with flex-direction: row to align its contents horizontally.
header {
display: flex;
flex-direction: column;
gap: 1rem; /* spacing between rows */
}
.logo-row,
.nav-row,
.search-row {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 0.5rem;
}
The Pattern
Think of it like a sandwich: the outer container (header) is the plate that holds everything vertically stacked. Each layer (logo, nav, search) is its own horizontal flex container that arranges its ingredients side-by-side. You're nesting flex containers—column on the outside, rows on the inside.
This approach gives you clean separation between header sections, makes responsive design easier (you might collapse or reorder rows on mobile), and keeps each row's alignment independent.
Key Takeaway: A multi-row header uses flex-direction: column on the header container to stack rows, with each row being its own horizontal flex container—combining vertical stacking with horizontal alignment for complex, maintainable layouts.