How is “grid-template-rows: auto auto 1fr auto” interpreted?

As a thumb rule,

  • fr is greedy,
  • auto is shy.

When the browser renders your grid, first it calculates the necessary sizes of auto elements – they all get the minimum they can live with -, and then, after all other sizes are known, will it distribute the remaining space among fr cells. Distribution works the obvious way: sum the numbers, slice the pie, give everyone the amount requested. Like, you have 1fr, 1fr, 3fr and 2fr in the definitions – the numbers add up to 7, therefore the remaining space will be cut to 7 equal slices, and then everyone gets their share.

Splitting horizontal space

Remember this one and grids will be your best friends:

  • 1fr 1fr 1fr ——–> 3 equal columns,
  • auto auto auto —-> 3 adaptive-width columns

Leave a Comment