I am trying to make a list of items in a flex container, but I do not know how many of them will show up. The items are stretching to fill the container and their widths start on flex-basis: 125px. On my web, the container can be resized by a user which might cause troubles. The problem is, that by the end, there are sometimes fewer items than on any other row. That means that the items in the last row stretch differently and "do not follow the grid". How can I make them follow the grid?
Here is a link to JSFiddle, where you can see a demo of my problem. If you resize the output window, you'll see, why the code does not cooperate with me. I have already tried to add .container::after that would somehow fill the space to make the last row to follow the grid, but it just doesn't allow the last items to overgrow "too much".
The basic CSS is this:
.container{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.item{
flex-basis: 125px;
flex-grow: 1;
}
I would like to have it the way, that if the user resizes the window, it would go like this:
But in my case, it goes like this: