I use css grid to resize the columns and move them to new rows when they don't fit. Here is the code that explains everything:
.tiles-container { display: grid; grid-gap: 6rem; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 2fr)); } a { background: red; height: 100px; }
<div class="tiles-container"> <a></a> <a></a> <a></a> <a></a> </div>
grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 2fr));
Now, what I want to avoid is moving only one (single) column to a new row. Instead, it collapses earlier and moves the 2 columns together.
To explain it more intuitively, this is acceptable:
█ █ █ █
Also:
█ █ █
██
Also:
██
██
This is unacceptable:
█ █ █
█
I want to avoid unnecessary media queries here. This is my code: https://jsfiddle.net/tucado/0czokyxa/3/
If anyone encounters the same problem, here is the solution: https://jsfiddle.net/tucado/0czokyxa/5/
and CSS:
Thank you @Temani-Afif