I've been reading stack overflow questions and other blogs on what flex-basis
is supposed to do, but I still can't fully grasp how it affects the behaviour of an element.
Here's an example with my code:
.item {
background-color: red;
border: 1px solid pink;
margin: 10px;
padding: 10px;
}
.container {
display: flex;
}
.container .item {
height: 50px;
flex-grow: 1;
}
.container3 {
flex-direction: row;
width: 500px;
}
.container3 .a,
.container3 .b {
flex-basis: 200px;
}
<div class="container container3">
<div class="item a">Segmentation fault</div>
<div class="item b">Null pointer exception</div>
<div class="item c">hello</div>
<div class="item d">hello</div>
</div>
I set flex-basis
to 200px for items a
and b
but they are both shorter than 200px
width. I was under the impression that flex-basis
is the "initial" width of the item, meaning "min-width" of an item. But clearly that's not true, so I don't understand what "initial" means.
What is the specific mathematical formula that calculate the width of item a
and b
when a pixel value is given for flex-basis
?