The Mozilla Developer Network flex article says of its syntax:
One-value syntax: the value must be one of:
- a unitless
<number>: then it is interpreted as<flex-grow>.- a valid value for width: then it is interpreted as
<flex-basis>.- one of the keyword values
none,auto, orinitial.
The second bullet implies that flex: 20%; is equivalent to flex-basis: 20%;, as 20% is a valid value for width.
However, that is not the case in practice:
.container {
display: flex;
}
.container>div {
padding: 6px;
}
.one {
background: #fcc9e5;
flex: 20%;
}
.two {
background: #ecaef9;
flex: 1;
}
<div class="container">
<div class="one">one</div>
<div class="two">two</div>
</div>
.container {
display: flex;
}
.container>div {
padding: 6px;
}
.one {
background: #fcc9e5;
flex-basis: 20%;
}
.two {
background: #ecaef9;
flex: 1;
}
<div class="container">
<div class="one">one</div>
<div class="two">two</div>
</div>
So, what is happening here?