I hope someone can help me, I cannot for the life of me understand how the auto-fit/fill in grid layouts work. I know basic CSS but I have never worked with the grid layout before.
I have a large number of checkbox items with labels, which I want to arrange in several columns (depending on screen size), with column flow.
I have managed to use
grid-template-columns: repeat( auto-fit, minmax(200px, 1fr) );
which gives me almost the right thing, but as soon as I add
grid-auto-flow: column;
it outputs only 1 row with hundreds of columns. I've tried reading articles on how this works, and tried different configurations of grid-row-template and grid-column-template but I cannot get a satisfactory result. I don't want to specify an exact number of rows, as the number of items may change, it should just fill them in as needed while keeping the columns fitting on screen and the same width.
I will try and add a sample of my code, I hope it makes sense as I am using Smalltalk to pull the checkbox items from a repository and to print HTML to the browser.
Styles
.grid-container {
font-size: .7em;
display: grid;
}
.grid-container--fit {
grid-template-columns: repeat( auto-fit, minmax(250px, 1fr) );
Smalltalk printing the HTML, iterates to generate each checkbox element.
aHTML nextPutAll: '<form><div class="grid-container grid-container--fit">'.
subjectItems do: [ :i | aHTML nextPutAll: '<label><input type="checkbox" name="subjects" value="', i description, '">', i description, '</label><br>' ].
aHTML nextPutAll: '</div></form>'.