I'm trying to distribute elements of a list vertically evenly while keeping them floating. The count of elements is dynamic, so is there string length. The height of the surrounding container is static. Here's an example:
----------------------------------
| element1 | element2 | element3 |
| |
| el4 | el5 | element6 | elem7 |
| |
| el8 | element9 | element10 |
| |
| |
| |
----------------------------------
This is desired:
----------------------------------
| element1 | element2 | element3 |
| |
| |
| el4 | el5 | element6 | elem7 |
| |
| |
| el8 | element9 | element10 |
| |
----------------------------------
As I don't know how many elements are in the container, I can't distribute them into table rows. As you can see in the example, line 2 contains 4 elements whereas line 1 and 3 carry 3 elements.
I tried working with line-height
but that's not dynamic. If I get more elements, line-height would have to decrease accordingly.
I thought about detecting the element count as in Can CSS detect the number of children an element has? but that doesn't cover different widths of the elements. The pure count doesn't help here.
Any ideas on how to solve that problem using pure CSS?