Is there a way to force all items in the last row of the grid to fill that row, no matter how many they have?
I don't know the number of items in the grid, so I can't target them directly. I tried using grid-auto-flow:ensemble
but it didn't really help.
This is a visualization of my problem: :
div { margin:20px auto; width: 400px; background: #d8d8d8; display: grid; grid-gap: 10px; grid-template-columns: repeat(3, 1fr); } span { height: 50px; background: blue; }
<div> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div>
This is entirely possible with CSS Grid by combining the CSS rules nth-child and nth-last-of type. The only thing to note is that the number of columns needs to be known in advance.