NexusBerry Modern Frontend Course
By Rana M. Ajmal | February 2026
Part 1
Analogy: Items on a shelf — one direction at a time
Items flow left to right
Main axis: horizontal
Cross axis: vertical
flex-direction: row;
Items flow top to bottom
Main axis: vertical
Cross axis: horizontal
flex-direction: column;
justify-content works along the main axis. align-items works along the cross axis.
display: flex only affects direct children — not grandchildren!
| Property | What It Controls | Common Value |
|---|---|---|
display: flex | Activate Flexbox | flex |
flex-direction | Main axis direction | row / column |
flex-wrap | Allow wrapping | nowrap / wrap |
justify-content | Main axis alignment | space-between |
align-items | Cross axis alignment | center |
gap | Space between items | 16px |
💻 Let's see this in code!
Switch to VS Code — building a Flexbox navigation bar
.container {
display: flex;
flex-direction: column;
}
What happens to the child elements?
flex-direction: column changes the main axis from horizontal to vertical.
Difference between space-between and space-around?
space-between: no edge space. space-around: equal space around each ✅space-between only works with 2 itemsspace-around centers everythingspace-between pushes first/last to edges. space-around gives each item equal space on both sides.
.container {
display: flex;
align-items: space-between;
}
space-between is NOT valid for align-items!
align-items accepts: stretch, flex-start, flex-end, center, baseline. The space-* values only work with justify-content.
gap instead of margins between flex itemsPart 2
Analogy: flex-grow = dividing pizza slices 🍕
flex-grow: 1 | flex-grow: 2 | flex-grow: 1 — ratio 1:2:1
Total grow = 1+2+1 = 4 parts. Each item gets its share of extra space.
flex: 1 Shorthand
flex: 1;
/* Expands to: */
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0%;
flex: 1 handles 90% of your Flexbox needs. Master this one shorthand.
Starts from content size
Wider content = wider item
Default behavior
flex: 1 1 auto;
Ignores content size
All items equal width
What flex: 1 uses
flex: 1; /* = 1 1 0% */
| Property | What It Does | Default |
|---|---|---|
flex-grow | How much item grows | 0 |
flex-shrink | How much item shrinks | 1 |
flex-basis | Starting size | auto |
flex | Shorthand (grow shrink basis) | — |
align-self | Override parent's align-items | auto |
order | Visual order (without changing HTML) | 0 |
💻 Let's see this in code!
Switch to VS Code — building equal-width cards with a featured card
.item-a { flex-grow: 1; }
.item-b { flex-grow: 2; }
.item-c { flex-grow: 1; }
/* 400px extra space to distribute */
How is the extra space distributed?
Total grow = 4. A gets 1/4 (100px), B gets 2/4 (200px), C gets 1/4 (100px).
What does flex: 1 expand to?
flex-grow: 1; flex-shrink: 0; flex-basis: auto;flex-grow: 1; flex-shrink: 1; flex-basis: 0%; ✅flex-grow: 1; (nothing else)flex: 100%;The 0% basis is key — items ignore content size and share space equally.
5 cards in a row squish too much on small screens. How to make them wrap?
flex-direction: wrap;flex-wrap: wrap; ✅display: flex-wrap;overflow: wrap;flex-wrap: wrap allows items to flow to the next line. Essential for responsive layouts!
flex: 1 = equal-width items (the 90% shorthand)flex-grow distributes extra space proportionallyflex-wrap: wrap makes flex layouts responsiveflex: 1 instead.
Part 3
Analogy: Grid = spreadsheet — rows AND columns
Row OR column
Content-driven layout
Items decide the flow
Best for components
Rows AND columns
Layout-driven design
YOU define the grid
Best for page layout
display: grid;
grid-template-columns: 1fr 2fr 1fr;
gap: 16px;
On 800px: 1fr = 200px, 2fr = 400px, 1fr = 200px (total 4 fr parts)
fr = fraction of remaining space. Only works inside grid-template-columns/rows.
display: grid
grid-template-columns
grid-template-rows (optional)
gap
grid-column)
| Code | What It Does |
|---|---|
grid-column: 1 / 3 | Span from line 1 to line 3 (2 columns) |
grid-column: 1 / -1 | Span from first to last line (full width) |
grid-column: span 2 | Span 2 columns from current position |
grid-row: 1 / 3 | Span from row line 1 to 3 (2 rows) |
-1 means “the last line.” grid-column: 1 / -1 = full width regardless of column count.
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 16px;
}
💻 Let's see this in code!
Switch to VS Code — building grid layouts & the magic pattern
.container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
/* Container: 800px, gap: 0 */
}
How wide is each column?
Total = 4fr. 800 ÷ 4 = 200px per fr. Columns: 200 | 400 | 200.
What does grid-column: 1 / -1 mean?
-1 = the last grid line. Works regardless of how many columns you have.
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
Responsive grid — no media queries needed!
Resize the browser: 4 cols → 3 → 2 → 1 — automatically.
fr unit = fraction of remaining spaceauto-fit + minmax = responsive without media queriesPart 4
Grid for the big picture, Flexbox for the details
• Navigation bars
• Button groups
• Card internals
• Centering elements
Component-level (micro)
• Page layouts
• Card grids
• Dashboard structure
• Complex 2D layouts
Page-level (macro)
💻 Let's build the dashboard!
Switch to VS Code — combining Grid & Flexbox
4 cards per row on desktop, 1 per row on mobile. Best approach?
repeat(auto-fit, minmax(250px, 1fr))Grid gives you cleaner 2D control with one line. Flexbox needs more setup.
.dashboard {
display: grid;
display: flex;
}
NOT a syntax error — but a likely copy-paste mistake!
display overrides the first. The element becomes flex, not grid. Did you mean to do that?
| Layout Need | Tool |
|---|---|
| Nav bar (logo + links) | Flexbox |
| Page with header, sidebar, main, footer | Grid |
| Centering one element | Both! |
| Auto-wrapping card grid | Grid (auto-fit + minmax) |
| Container | Common Value |
|---|---|
display: flex | Activate Flexbox |
flex-direction | row / column |
justify-content | space-between / center |
align-items | center / stretch |
gap | 16px |
Flex item shorthand: flex: 1 = grow: 1, shrink: 1, basis: 0%
| Grid Property | Example |
|---|---|
display: grid | Activate Grid |
grid-template-columns | 250px 1fr |
grid-column: 1 / -1 | Full-width spanning |
Magic pattern: repeat(auto-fit, minmax(250px, 1fr))
| Need | Tool |
|---|---|
| Nav bar, button group | Flexbox |
| Page layout, card grid | Grid |
Full cheat sheet shared after class
repeat(auto-fit, minmax(...))Due: Before Lecture 5 | Submit via Google Classroom
Total: 100 points | See assignment.md for full rubric
Next Lecture: Advanced CSS & Responsive Design
Media queries, mobile-first strategy, responsive units
NexusBerry Training and Solutions
www.nexusberry.com | admin@nexusberry.com
WhatsApp: 0328-4500073