Why items dont shrink in inline-flex. But it works fine in normal flex. Maybe it is supposed to work that way, I dont know. Maybe it is somewhere in the spec but I coudn't find anything related. I would be grateful if someone could explain this.
.container {
width: 100px;
margin 0 auto;
margin-top: 100px;
background-color: green;
}
.inline-flex {
display: inline-flex;
margin-bottom: 10px;
}
.flex {
display: flex;
}
.item {
width: 50px;
height: 50px;
margin-right: 5px;
background-color: blue;
}
<div class="container">
<div class="inline-flex">
<div class="item">no-shrink</div>
<div class="item">no-shrink</div>
<div class="item">no-shrink</div>
</div>
<div class="flex">
<div class="item">shrink</div>
<div class="item">shrink</div>
<div class="item">shrink</div>
</div>
</div>
As stated before,
flexacts like ablockandinline-flexlikeinline-blockon the outside and their children behave identically. The flex-items.itemare acting totally different when they should appear the same because their behavior is influenced by the flex-container (.flexand.inline-flex). Aside from the flex-containers having differentdisplayvalues, there are no other differences..itemof.inline-flexhas retained it's width of 50px.itemof.flexhas a width of 34.6687pxI still haven't figured out why this is but I have 3 different solutions:
.containeris too small, increase it's width.See Example A
Figure I
Change the
flexproperties of.items or assignmin-widthSee Example B
Figure II