I’d like to render a list of items either horizontally or vertically, depending on available horizontal space. The contents of the list items may change dynamically, so @media queries don’t really help.
Example:
item1 item2 item3 item4 |<-- right border of parent box
Now we change item2 to muchlongeritem2 and the layout should change to:
item1 |
muchlongeritem2 |<-- right border of parent box
item3 |
item4 |
Is there a way to achieve this using only CSS? I could come up with a JavaScript solution, but if someone has some code ready I’d be happy to check it out, too.
I’ve used something similar recently, here’s a snippet: