Advanced Grid Paddy — CSS

Grid's ultimate moves: 7 levels of subgrid, implicit vs explicit grids and dense packing. An advanced CSS Grid game for designers of complex layouts.

What you learn in this game

repeat(count, pattern) repeats a column or row pattern. repeat(3, 1fr) is three equal columns, shorter than writing 1fr 1fr 1fr.

minmax(min, max) gives a column its smallest and largest size. Inside repeat(), columns can grow with the space without ever going below their minimum.

auto-fill inside repeat() makes as many columns as fit. The number of columns changes as the container widens or narrows, with no media query.

grid-template-areas lays out the grid with area names you can read like a picture. Each element goes into its area with grid-area: name.

grid-auto-flow: dense changes how the grid places plots. Small plots may move back to fill a gap a large plot left; without dense, the gap stays empty.

The grid makes new rows itself when its plots go past the template. grid-auto-rows sets the height of those automatic rows (the implicit grid); the default is auto.

What the levels ask

  1. Six plots in three equal columns, the way this paddy has always been. Set grid-template-columns on #grid using repeat() and the fr unit.
  2. Three rice plots may grow wider, but never narrower than 150 px, on Nenek's narrow field too. Use minmax() inside repeat() for grid-template-columns.
  3. Nenek's fields are not all the same width. Make as many columns as fit, each at least 120 px and free to grow: repeat() with auto-fill and minmax(). Leave the columns that get no plot empty.
  4. Rara names the plots like a web page: header stretched across the top, sidebar (the seedbed) bottom left, main (the rice field) bottom right. In sawah.html, #main comes before #sidebar. Map it with grid-template-areas on #layout, then give each plot its grid-area.
  5. Two rice plots two columns wide, then three corn plots. Now the top right corner is bare land, and weeds grow fast there. Fill the gap with dense placement through grid-auto-flow.
  6. The rows of this field are made automatically. Every row is at least 80 px, but the row with the scarecrow (#orangan) has to grow as tall as the scarecrow. Set grid-auto-rows with minmax(): a lower bound of 80 px, an upper bound of auto.
  7. The whole paddy laid out like a page: hdr across the top, side (the seedbed) on the left, content (the rice field) on the right, ftr across the bottom. In sawah.html, #content comes before #side. Map it with grid-template-areas on #page and give each plot its grid-area.
  8. Only two plots this season. Columns are still at least 150 px, but empty columns close so the two plots stretch across the field: use auto-fit, not auto-fill.
  9. The main rice plot, #hero, runs three columns wide on the top row. Use grid-column with the span keyword.
  10. The corn in #tall grows tall, so its plot runs two rows down. Use grid-row with span.
  11. This field has four columns, so it has five lines, numbered 1 to 5 from the left. The plot #banner starts on line 1 and stops on line 4. Write grid-column as start line / end line.
  12. In the field's CSS, the rice plot uses grid-column: start / mid and the seedbed grid-column: mid / end. Name the lines on #grid: two 1fr columns, with the lines [start], [mid] and [end].

And more, 20 levels in all.