grid-template-columns: repeat(4, 1fr)
grid-template-columns: 1fr minmax(50px, max-content) 1fr;
grid-template-columns: repeat(4, 50px 100px)
auto-fill
will fill each row with the column's intrensic width. If the viewport is wider, the row will fill with empty columns of the same width. grid-template-columns: repeat(auto-fill, 100px 1fr)
auto-fit
will fill each row with the column's intrensic width. If the viewport is wider, the columns will expand to fit the viewport. Additional zero width columns will be added corresponding to the expanded width. grid-template-columns: repeat(auto-fit, 100px 1fr)
grid-auto-rows: 25px 100px
automatically creates as many rows as needed following the specified pattern: 25px 100px
grid-template-columns: 50px 1fr;
grid-template-rows: 70px 100px;
grid-auto-flow: row;
grid-auto-flow: row;
is the default so need (almost) never be specified.
grid-auto-flow: column
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 3.5em;
grid-auto-rows: 4.5em 3.5em;
grid-template-rows: 3.5em.
Only 1 row specified. grid-auto-rows: 4.5em 3.5em;
creates a pattern of rows as needed.grid-template-columns: max-content 1fr min-content 3fr;
max-content
will size the element to the full length of the content. It will not wrap.
min-content
will size the element to the width of the longest single content. All else will wrap.
min-content and max-content
will work on any element that takes a width property.
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
The auto-fill function allows the grid to line up as many grid tracks (columns or rows) as possible without overflowing the container. This can create similar behavior to flex layout's flex-wrap: wrap
.
The minmax()
function sets a minimum and maximum size range for a grid track
Any fixed size will work. fr
units will work. %
widths are less successful.
grid-template-columns: 100px 200px repeat(auto-fill, minmax(300px, 1fr));
This uses the default: justify-items: stretch
. To keep the cards a fixed size, use justify-items: center