Is their an simple way in CSS to have a fixed maximum of child items on the same line, before you push the next child elements to a new line?
As i understand flexbox, child items only get pushed to a new line if their isint enough available space on the line above it. But i am seeking a CSS rule or function that let me say "i want a maximum of 3 child items on any given line, and even if space is available for a 4'th one push it to a new line".
Or you could use CSS Grid for this:
Your HTML:
Your CSS:
I'm sure there are more efficient ways to write this with grid. But this does the job.
fiddle
You could place the items inside a container div that has a width of 100% and a max-width that is just enough to fit three items inside it?
And then place this around all the items.
Use flex-basis.
The percentage must be adapted according to you box-sizing model, and the use of margins and/or padding.
Instead of using display: flex you could use float: left and clear every 3rd child node like this:
I created a fiddle for you: fiddle example
In the case that the parent can hold only two children, you could use this short jQuery fix:
Fiddle with fix: fiddle example2
If you are using it with bootstrap you shoul add this css for pseudo row class