A pure flexbox Solution is just:
flex: 1
The Problem
flex: 1 is a shorthand to set flex-grow to 1, BUT they are not the same.
flex: 1
means:
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;// !!!
When using flex-grow: 1
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;// oops !!!
flex-basis: auto
- If an item has a width set the size will be based on that width.
In your case by writing to your <span>
you are actually expanding your first <div class="half">
flex-basis 0
- The item size is not taken into consideration for the space-sharing calculation.
In your case the first and second <div>
will have equal width regardless of their actual size.
To see the difference set your width to an absolute (fixed) value:
.flexContatiner
{
width: 500px;
}
Best documentation on these topics can be found here:
Controlling ratios of flex items along the main axis
To see more detailed answers from other Devs on flex-1
and flex-grow
see below links:
The difference between flex:1 and flex-grow:1
To me this one was the best explained/illustrated!
Make flex-grow expand items based on their original size