Description
Section 2.3 starts with the following example:
The following example justifies all columns by distributing any extra space among them, and centers the grid in the grid container when it is smaller than 100vh.
main { grid: auto-flow 1fr / repeat(auto-fill, 5em); min-height: 100vh; justify-content: space-between; align-content: safe center; }
Issues:
-
The example omits setting
display: grid
on the<main>
element, which means the grid properties are not applied. -
The example sets the implicit grid rows to
1fr
, which causes each row (or even a single row) to expand to fill the available vertical space dictated bymin-height: 100vh
. Regardless of whether there is one row or multiple rows, all the rows take up the full available height, leaving no extra vertical space for thealign-content: safe center
property to have an effect. -
The declaration
repeat(auto-fill, 5em)
creates as many 5em-wide columns as will fit along the inline axis, effectively consuming all available inline space. This means there is no leftover free space forjustify-content: space-between
to distribute among the columns, contrary to what the example’s description implies.
Suggested revision:
The following example vertically centers the grid in the grid container when it is smaller than 100vh.
main {
display: grid;
grid: auto-flow auto / repeat(auto-fill, 5em);
min-height: 100vh;
align-content: safe center;
}