This seems to be possible with a grid layout. First of all, to position your positions, you can use
grid-template-columns: repeat(auto-fill, 50px);
so that each element occupies 50 pixels, and it positions the elements in one line until there are no more elements in one line. And then you can use grid-column-start: 1; for a specific element so that it jumps to a new line.
* { box-sizing: border-box; } .flex { display: grid; grid-gap: 10px; grid-template-columns: repeat(auto-fill, 50px); border: 2px solid red; } .item { width: 50px; height: 50px; margin: 5px; border: 2px solid blue; } .new-string { grid-column-start: 1; background: red; }
<div class="flex"><div class="item"></div><div class="item"></div><div class="item"></div><div class="item new-string"></div><div class="item"></div><div class="item"></div><div class="item"></div><div class="item"></div><div class="item new-string"></div><div class="item"></div><div class="item"></div><div class="item new-string"></div><div class="item"></div></div>
source share