This defeats the goal of the grid system. A grid is a two-dimensional array in which everything has X and Y values, as in a spreadsheet.
Yes, you want a system in which elements are wrapped. Flexbox meets all requirements with flex-wrap .
#container { padding: 10px; width: calc((100px + (10px * 2)) * 4); display: flex; flex-wrap: wrap; background: blue; margin: 10px; } #container div { width: 100px; height: 100px; flex-grow: 1; background: red; margin: 10px; }
https://jsfiddle.net/0c0hzh8t/
This makes the children occupy all available space, which, if the line is full, will be zero and will have a standard size.
If you want the size of the container to be determined automatically, delete the width property and the size of the container and its elements will be changed automatically. This is just as good, but I assume you want to determine the number of elements in a row.
Jackhasakeyboard
source share