JavaScript Curriculum
Flexbox
mediumThe coffee shop page needs a proper navbar, a card grid, and a sidebar layout for the menu. Flexbox handles all three in fewer lines of code than you'd expect.
Flexbox
Flexbox (Flexible Box Layout) is a one-dimensional layout model — it arranges items in a row or column. It's the right tool for navbars, card rows, sidebars, centered content, and any layout where items need to grow, shrink, or align with each other.
The Container Properties
When you set display: flex on an element, its direct children become flex items. You control their arrangement from the container:
.container {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: flex-start;
flex-wrap: nowrap;
gap: 8px;
}Flex Item Properties
The power of Flexbox comes from controlling how individual items grow and shrink:
All items flex-grow: 1 — they share available space equally.
.nav {
flex: 0 1 auto;
/* flex-grow: 0 flex-shrink: 1 flex-basis: auto */
}.main {
flex: 1 1 auto;
/* flex-grow: 1 flex-shrink: 1 flex-basis: auto */
}.aside {
flex: 0 1 auto;
/* flex-grow: 0 flex-shrink: 1 flex-basis: auto */
}Real-World Flexbox Patterns
The same handful of patterns appear in almost every project:
Logo left, links centre, CTA right — the universal nav layout.
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
}Your Challenge
Build the coffee shop page layout using Flexbox — sticky header with logo and nav, two-column content area, and a card row.
Challenge
Build a full page layout using Flexbox: a header with logo left and nav right (justify-content: space-between), a main area with content and sidebar side by side (flex: 1 and flex: 0 0 240px), and a card row with flex-wrap: wrap and flex: 1 1 200px on each card.
Flexbox
mediumThe coffee shop page needs a proper navbar, a card grid, and a sidebar layout for the menu. Flexbox handles all three in fewer lines of code than you'd expect.
Flexbox
Flexbox (Flexible Box Layout) is a one-dimensional layout model — it arranges items in a row or column. It's the right tool for navbars, card rows, sidebars, centered content, and any layout where items need to grow, shrink, or align with each other.
The Container Properties
When you set display: flex on an element, its direct children become flex items. You control their arrangement from the container:
.container {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: flex-start;
flex-wrap: nowrap;
gap: 8px;
}Flex Item Properties
The power of Flexbox comes from controlling how individual items grow and shrink:
All items flex-grow: 1 — they share available space equally.
.nav {
flex: 0 1 auto;
/* flex-grow: 0 flex-shrink: 1 flex-basis: auto */
}.main {
flex: 1 1 auto;
/* flex-grow: 1 flex-shrink: 1 flex-basis: auto */
}.aside {
flex: 0 1 auto;
/* flex-grow: 0 flex-shrink: 1 flex-basis: auto */
}Real-World Flexbox Patterns
The same handful of patterns appear in almost every project:
Logo left, links centre, CTA right — the universal nav layout.
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
}Your Challenge
Build the coffee shop page layout using Flexbox — sticky header with logo and nav, two-column content area, and a card row.
Challenge
Build a full page layout using Flexbox: a header with logo left and nav right (justify-content: space-between), a main area with content and sidebar side by side (flex: 1 and flex: 0 0 240px), and a card row with flex-wrap: wrap and flex: 1 1 200px on each card.