This is what I need to achieve:
(Note the empty grey slots)
Which in flexbox layout should normally behave like this: (if flex-wrap is set to wrap)
I know that this could be achieved with a CSS grid layout
.parent {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
grid-column-gap: 0px;
grid-row-gap: 0px;
height: 400px;
}
.parent div {
border: 1px solid;
box-sizing: border-box;
}
div:nth-child(1) { grid-area: 1 / 1 / 2 / 2; }
div:nth-child(2) { grid-area: 1 / 2 / 2 / 3; }
div:nth-child(3) { grid-area: 1 / 3 / 2 / 4; }
div:nth-child(4) { grid-area: 2 / 1 / 3 / 2; }
div:nth-child(5) { grid-area: 2 / 2 / 3 / 3; }
div:nth-child(6) { grid-area: 3 / 1 / 4 / 2; }
div:nth-child(7) { grid-area: 3 / 2 / 4 / 3; }
<div class="parent">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
The thing is that I would like to use with justify-content: space-between or gap as in my scenario the child elements are narrower and not feeling so comfortable with css grid.
Example:
.parent {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.parent div {
border: 1px solid;
box-sizing: border-box;
width: calc(33% - 4px);
height: 150px;
margin-bottom: 8px;
}
/* just to illustrate: child(6) */
.parent div:nth-child(6) { transform: translate(calc(-100% - 8px), calc(100% + 8px)); }
<div class="parent">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
Can this be done with flex?
There are 7 elements now but there will be more eventually, so this needs to be scaleable. Also, I'd rather not have to change the markup if possible.
