With the repeat()
and auto-fit
/ auto-fill
functions it's easy to get grid items to wrap when there is a defined length pattern for the columns or rows.
In the example below, all columns are a minimum width of 100px and maximum width of 1fr.
#grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
grid-gap: 1em;
}
#grid > div {
background-color: #ccddaa;
padding: 10px;
}
<div id="grid">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
But when the tracks have no length pattern (i.e., lengths vary randomly), how can grid items be made to wrap?
In the example below, the first column is 60% width. The second column is min/max 250px/1fr. How can I get the second column to wrap on smaller screens?
#grid {
display: grid;
grid-template-columns: 60% minmax(250px, 1fr);
grid-gap: 1em;
}
#grid > div {
background-color: #ccddaa;
padding: 10px;
}
<div id="grid">
<div></div>
<div></div>
</div>
I know flexbox and media queries provide solutions, but I'm wondering if Grid Layout can do this. I searched the spec but didn't find anything. Maybe I missed the section. Thanks for your help.