Lesson 27 of 50
cssCSS Grid – Fundamentals
15 mins
Course progress54%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 27 of 50
css15 mins
Keep these ideas in mind as you work through the lesson.
CSS Grid is a two‑dimensional layout system that gives you rows and columns at once – perfect for complex page skeletons.
.container {
display:grid; /* turns on grid layout */
grid-template-columns: repeat(12, 1fr); /* 12 equal tracks */
gap:1rem; /* space between cells */
}
grid-template-columns defines track sizes (columns). 1fr distributes free space equally.grid-template-rows works the same for vertical tracks.gap (formerly grid-gap) adds a gutter; works for both axes..item {
grid-column: 2 / span 4; /* start at column‑2, span 4 columns */
grid-row: 1 / 3; /* from row‑1 to row‑3 (exclusive) */
}
grid-area to define both column and row at once.<div class="container">
<aside class="sidebar">Sidebar</aside>
<main class="main">Main content</main>
</div>
.container { display:grid; grid-template-columns: repeat(12,1fr); gap:1rem; }
.sidebar { grid-column:1 / span 3; }
.main { grid-column:4 / span 9; }
grid-auto-rows/grid-auto-columns to control their size.fr unit – Unlike percentages, fr units are relative to the free space after deducting non‑flexible tracks (e.g., fixed‑width columns).When you rearrange DOM order with grid-column/grid-row, screen readers still read the source order. Be mindful of the logical flow; avoid reordering critical navigation without ARIA adjustments.