css · level 2 · unit 3 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
places children in rows and columns.
Flexbox thinks about one line at a time. A grid thinks in rows and columns together, like a chessboard. Switch it on with display: grid on the parent.
grid-template-columns lists the width of each column, which is one . 80px 80px 80px makes three columns of 80px. The children fill the cells one after another, left to right.
When a row is full, the next child starts a new row. gap works in a grid too, between rows and between columns.
<div class="week">
<div class="day">Mon</div>
<div class="day">Tue</div>
<div class="day">Wed</div>
<div class="day">Thu</div>
<div class="day">Fri</div>
<div class="day">Sat</div>
</div> .week {
display: grid;
grid-template-columns: 80px 80px 80px;
gap: 8px;
}
.day {
padding: 12px;
background-color: lightblue;
} Press show my page to see it here.
Add a fourth 80px and the six days rearrange into rows of four.
guess first
Three columns and seven children. How many rows?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<div class="grid">
<div class="cell">1</div>
<div class="cell">2</div>
<div class="cell">3</div>
<div class="cell">4</div>
<div class="cell">5</div>
<div class="cell">6</div>
<div class="cell">7</div>
</div> .grid {
display: grid;
grid-template-columns: 60px 60px 60px;
gap: 4px;
}
.cell {
background-color: thistle;
}
your turn
Your turn. Make a photo grid.
Make the gallery a grid with three columns of 100px. The gap is done for you.
the page you’re styling
<div class="gallery">
<img src="cat.svg" alt="A cat">
<img src="dog.svg" alt="A dog">
<img src="tree.svg" alt="A tree">
<img src="cake.svg" alt="A cake">
<img src="ball.svg" alt="A ball">
<img src="logo.svg" alt="A logo">
</div>your css
Press show my page to see it here.
- the gallery is a gridnot checked yet
- there are three 100px columnsnot checked yet
fix it
The board shows one long column. Fix it!
the page you’re styling
<div class="board">
<div class="tile">X</div>
<div class="tile">O</div>
<div class="tile">X</div>
<div class="tile">O</div>
<div class="tile">X</div>
<div class="tile">O</div>
</div>your css
Press show my page to see it here.
- there are three 90px columnsnot checked yet
- The browser skipped the column list. Look at what sits between the sizes.
- Grid sizes are separated by spaces, not commas.
- Remove the two commas, then press run.
nailed it
you built your first grid. :D
display: gridplaces children in rows and columns.grid-template-columnslists each column's width, separated by spaces.- Children fill the cells in order, row by row.
new words in your collection
- grid
- track
- cell
This lesson isn’t saved. A free account remembers every lesson you finish.