Skip to main content

Common Flexbox Patterns

Practical examples of Flexbox in the real world.

1. Centering a Hero Component

.hero {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
min-height: 80vh;
}

Using Flexbox on the body to push the footer to the bottom of the page.

body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
main {
flex: 1; /* Takes up all available space */
}

3. Navigation Bar

nav {
display: flex;
justify-content: space-between;
align-items: center;
}

4. Cards Grid

.grid {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.card {
flex: 1 1 300px; /* Grow, Shrink, but start at 300px */
}