According to MDN, the flex: 1 shorthand should set flex-basis: 0. However, it actually sets flex-basis: 0%, and even more surprisingly this has different behaviour.
In the example below, I expect div.middle to shrink and scroll because it's been given overflow-y: auto and flex: 1, which should also imply flex-basis: 0. But it doesn't - the entire body scrolls instead because it refuses to shrink. If you uncomment the explicit flex-basis: 0, it then works correctly.
body {
text-align: center;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 0;
}
.outer {
min-height: 100%;
display: flex;
background: #99f;
flex-direction: column;
}
.middle {
background: #f99;
flex: 1;
/*flex-basis: 0;*/
overflow-y: auto;
}
<div class='outer'>
<div class='top'>top</div>
<div class='middle'>
A
<div style='height:800px'></div>
B
</div>
<div class='bottom'>bottom</div>
</div>
I tested this in both Chrome 84.0 and Firefox 68.11.0esr and they both have the same unexpected behaviour.
- Why does
flex-basis: 0%differ fromflex-basis: 0? - Why does
flex: 1setflex-basis: 0%instead offlex-basis: 0?