Grid
Change a control, or edit the CSS. The preview uses that same CSS.
Click a cell. Notes spans from the first cell through the one you clicked.
Numeric changes ease so you can watch them.
The preset changed the tracks, and the click changed where Notes ends. grid-column and grid-row in the CSS updated to the lines you clicked. The item did not move because a class changed. The line numbers did.
Four mechanisms can place this note. Switch them and watch which ones match.
.parent {
display: flex;
justify-content: center;
align-items: center;
}The parent centers the note on both axes.
+Go deeper
Tracks are the columns and rows
display grid makes the children grid items. then defines the tracks. grid-template-columns of 1fr 1fr 1fr is three equal columns. 1fr 2fr 1fr makes the middle track twice as wide as either side. 140px 1fr is a fixed sidebar and a flexible remainder. Items fall into those cells in reading order until you place one yourself. was one axis. Grid is both axes at once. The switch above adds the fourth way to center a note: place-content center on a grid parent. It matches the flex result. Margin auto still only centers horizontally.
Lines are numbered from 1
Three columns have four vertical lines, numbered 1 to 4. The first cell sits between line 1 and line 2. You count lines, not cells, when you write a span.
A span is two lines
grid-column: 1 / 3 covers from line 1 up to but not including line 3, which is two columns. grid-row works the same way. Clicking a cell in the playground sets the end line to the cell you chose. The start stays at line 1 so the change is easy to see.
| Preset | Columns | Use it when |
|---|---|---|
| equal | 1fr 1fr 1fr | The columns should share the width |
| sidebar | 140px 1fr | One track is a fixed sidebar |
| custom | 2fr 1fr 80px | The tracks should not match each other |
A preset is a template
The buttons rewrite grid-template-columns and grid-template-rows. If you type a template the buttons do not list, the control shows a custom value and the preview still uses your CSS. That is the same sync as the other playgrounds.
Gap is not a track
Gap sits between tracks. It is not a column you can span into. Changing the gap slider does not change grid-column. It only changes the space between the cells.
Guided challenge
Grid
The columns declaration is 1fr 1fr 1fr. The script prints the sidebar template instead. Read the columns value from the style attribute.
Your console output appears here.
EXPECTED CONSOLE OUTPUT
grid 1fr 1fr 1fr 1 / 2 Notes
Hints 0/2
Use all hints or make 3 failed runs (0/3).
Free sandbox
Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.
Your console output appears here.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 150 XP. You can always revisit it.