🌐CSS Grid
Also known as Grid Layout, CSS Grid Layout, display: grid
A CSS layout that puts things in rows and columns at the same time.
Think of it like
It is like a muffin tray. Each cup has a row and a column. A big muffin can fill two cups.
Example
Jack shows twelve photos with grid-template-columns: repeat(3, 1fr). They fall into four neat rows of three.
Why it matters
Whole page layouts used to need tricks. Grid does them in a few lines.
Definition
Example code
css
.gallery {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
}Common mistake
Key takeaways
- 1Two directions. Rows and columns together.
- 2Cells to fill. Items drop into the next free cell.
- 3Span cells. One item can cover several cells.