Summary
In this lesson, we learned that:
- CSS Grid lays out elements in rows and columns at the same time. The element with
display: gridis the grid container, and its direct children are the grid items. - The columns are set with
grid-template-columns: each value creates one column, for example200px 1fr. Rows are created automatically as needed (or set withgrid-template-rows). - The
frunit is one share of the free space:1fr 1fr 1frcreates three equal columns that adapt to the width of the container. repeat(3, 1fr)is a shorter way to write1fr 1fr 1fr.gapsets the space between the rows and the columns (only between the cells, not at the edges of the grid). With two values, the first one is for the rows and the second one for the columns;row-gapandcolumn-gapset them separately.- Grid lines are numbered from 1. The
grid-columnandgrid-rowproperties say which columns and rows an item takes up:span 2takes up two of them,1 / 3everything between lines 1 and 3, and1 / -1all of them. grid-template-areasdraws a layout from named areas, one string for each row, andgrid-areaputs an element into an area.- Flexbox is for one direction (a row or a column), grid for two (rows and columns). They are often combined: grid for the layout of the page, flexbox for the parts inside it.
In the next lesson, the final project awaits you: you'll style a whole page on your own and use everything you've learned in the CSS course.
Instructions
Congratulations on completing the lesson! The editor contains your final code from this lesson. Try changing it: for example, add a seventh card, or move the menu to the right side by changing grid-template-columns and grid-template-areas.
Start programming for free
7/7