I want to make a box grid with flexbox. I want to be able to define a fixed width, have line wrapping, the line should be floating to left, center or right. Every other line should be filled with the max width of the page, but keep the fixed width of the box. This means that the space between should be variable.
Right now it seems to work for me on every line except the first, where it has some weird space before the first one. The last line craps out too if the amount of boxes fit the maximum.


My markup code is
<grid>
<box>
box
</box>
</grid>
And the CSS (SCSS) is
grid {
margin-bottom: 10px;
display: flex;
flex-wrap: wrap;
overflow: hidden;
justify-content: space-between;
&:before,
&:after {
width: 0;
content: " ";
display: table;
}
box {
margin-bottom: 5px;
min-width: 150px;
display: flex;
border: 1px #999 solid;
}
}
:before and :after are inside the grid, that's why space-between gets applied on them thus the ambiguous spacing..
And as for the alignment in the last line, I don't think there's a solution for that if you're using space-between.. If the number of grid items are finite, you can maybe give :after some width to make the last line items look left aligned
Emil Moe
Senior Data Engineer
Seems to be this part messing it up:
&:before, &:after { width: 0; content: " "; display: table; }I removed that, but still need to figure out, how I make the last line left align, not space between.