Mastering the 1-Dimensional Flexible Box Model with Live Controls & Recipes
Click the control buttons below to dynamically adjust justify-content, align-items, and flex-direction in real-time!
.container {
display: flex;
justify-content: flex-start;
align-items: stretch;
flex-direction: row;
gap: 12px;
}
flex-grow dictates what proportion of remaining available space each item claims.
/* Container distributes remaining width according to grow ratios */
.item-fixed { flex-grow: 0; width: 140px; }
.item-share1 { flex-grow: 1; }
.item-share2 { flex-grow: 2; } /* 2x growth factor */
Center anything horizontally and vertically with two flex properties:
.center-container {
display: flex;
justify-content: center;
align-items: center;
}
Using margin-left: auto; on a flex child automatically pushes it (and following siblings) to the far right end!
.nav-links {
margin-left: auto; /* Pushes the menu to the right! */
display: flex;
gap: 20px;
}
An avatar image next to descriptive content. flex-shrink: 0; prevents the avatar from squishing when text grows large.
Flexbox simplifies modern UI components. By setting flex-shrink: 0 on the media avatar, it maintains its geometric proportions even in constrained screen viewports.
.media-object { display: flex; align-items: flex-start; gap: 16px; }
.media-avatar { flex-shrink: 0; width: 64px; height: 64px; }
.media-content { flex-grow: 1; }