I have a container with a fixed width and a variable height. I fill the container with an unknown number of elements. I would like the elements to be arranged in columns from top to bottom, and then from left to right.
I could use column , but I do not know the maximum width of the children, so I can not set column-width or column-count .
I think display: flex with flex-flow: column wrap is the way to go, but if I support height: auto in the container, it will generate as a single column without wrapping the elements to use all available width.
Can I convince flexbox to use the entire available width and thereby minimize the height of the container? Would you suggest a different solution?
Fiddle: http://jsfiddle.net/52our0eh/
A source:
HTML:
<div> <span>These</span> <span>should</span> <span>arrange</span> <span>themselves</span> <span>into</span> <span>columns,</span> <span>using</span> <span>all</span> <span>available</span> <span>width</span> <span>and</span> <span>minimizing</span> <span>the</span> <span>container's</span> <span>height.</span> </div>
CSS
div { outline: 1px solid red; width: 100%; display: flex; flex-flow: column wrap; align-items: flex-start; } span { outline: 1px solid blue; }
source share