Please consider the following example:
.flexer {
display: inline-flex;
border: 1px solid red;
min-width: 0;
}
.extra {
flex: 0 1 0%; /* flex-grow: 0; flex-shrink: 1; flex-basis: 0%; */
min-width: 0;
transition: flex-grow .3s cubic-bezier(.4,0,.2,1);
overflow: hidden;
}
.flexer:hover .extra {
flex-grow: 1
}
<div class="flexer">
<div>
test
</div>
<div class="extra">
extra
</div>
</div>
<hr>
<div class="flexer">
<div>
test
</div>
</div> - How it should look, when not hovered
<br>
<div class="flexer">
<div>
test
</div>
<div>
extra
</div>
</div> - How it should look, when hovered
<br><br>
The red box should animate smoothly and precisely between the two widths (without delay).
I have trouble understanding why .flexer
(the parent) doesn't shrink when not hovered (e.g: the red box still remains full, instead of shrinking around test
).
From this q/a I understand adding min-width: 0
to the child should allow the parent to shrink. I've added it to both child and parent, to no avail.
Note 1: I'm more interested in understanding the mechanics and why this happens than finding an alternative solution (javascript, absolute positioning, etc...).
I'd like to use flexbox and I'd like to animate flex-grow
- or any other animatable flex prop - for this case, if at all possible.
Note 2: the markup is irrelevant (I'm open to changing it - e.g: adding a wrapper to any of the children, if that will make my example work).
Note 3: for a clearer understanding of the desired output, see the JS based answer I added after I realised this is not possible using only CSS.
Thanks for looking into this.