I have three block elements that I post using CSS Flexbox. (In my case, they seem to be two <select>s on either side of the <div>ider , I am <div>ider List Builder control.)
I want to:
- So that the middle element (separator) takes up the minimum amount of space.
- So that the element at both ends (that is: the selection controls) has a minimum width and grows to fill the possible space.
- To have all three elements on the same line when there is enough horizontal space in the container (for example: browser width)
- So that all elements are wrapped vertically when there is no horizontal space to place them horizontally.
Flexbox does a wonderful job on all these points, except for the last requirement. I can’t get all the elements to wrap if there is less space to have all of them on the same line.
I use a fairly simple flexbox setup to achieve the layout:
.container { display: flex; flex-wrap: wrap; flex-direction: row; align-items: center; } select { flex-basis: 10em; flex-grow: 1; } .divider { flex-basis: 3em; flex-grow: 0; text-align: center; }
The problem is that if the width of the container is set to any amount that is large enough for one choice plus a separator, it will complete the end selection, but not the divider. I will get a selection plus a separator on one line that looks ugly.
This script illustrates the problem:
http://jsfiddle.net/5s0yf74w/1/
Is it possible to achieve the desired result by customizing CSS while maintaining the overall flexbox layout?
source share