Grandma Marni’s goods shelf, built by Mr. Karim, is a real grid: write the tracks, gap and auto-flow, and the browser resolves 1fr to px, shows where the…
Flexbox shines in 1 dimension. A page layout (full-width header, sidebar, content, footer) is 2-dimensional, and there Grid wins outright: grid-template-columns + grid-column make a page structure in about 5 lines of CSS.
Grid is about lines, not cells
grid-template-columns: repeat(3, 1fr) but item 4 drops to a new row on its own That is an implicit row: the grid makes it itself for items that do not fit. grid-template-rows only sizes the rows you write; grid-auto-rows sizes implicit rows.justify-items and justify-content justify-items = where an item sits inside its cell. justify-content = where all the columns sit inside the container, only visible when the columns add up to less than the container.1fr column widens by itself because of long text 1fr = minmax(auto, 1fr): the column may not be narrower than its longest word. Use minmax(0, 1fr) so the share is even.1fr 2fr 1fr or 160px 1fr in grid-template-columns Watch the px numbers over the columns: the browser turns fr into real widths after the px and the gap are taken.1 / -1 in grid-column Good 1 covers every column. -1 = the last line, however many columns there are.repeat(auto-fit, minmax(120px, 1fr)), then slide width The number of columns changes with the width on its own. Responsive with no media query.