Performance: Flex grow and shrink
This affects how flex items resize within a container, impacting layout recalculations and paint times during resizing or dynamic content changes.
<div class="flex"> <div class="flex-grow flex-shrink basis-64">Flexible base size item</div> <div class="flex-grow flex-shrink">Flexible item</div> </div>
<div class="flex"> <div class="flex-grow-0 flex-shrink-0 w-64">Fixed width item</div> <div class="flex-grow flex-shrink">Flexible item</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed width with flex-grow/shrink mix | Low | Multiple on resize | High due to layout shifts | [X] Bad |
| Consistent flex-basis with grow and shrink | Low | Single on resize | Low, smooth resizing | [OK] Good |
flex-grow-0 do to a flex item?flex-grow-0 sets flex-grow to 0, meaning the item will not grow to fill extra space.flex-shrink-0 sets flex-shrink to 0, preventing the item from shrinking.<div class="flex w-64"> <div class="flex-grow-0 w-16 bg-blue-500">A</div> <div class="flex-grow w-32 bg-red-500">B</div> </div>
flex-grow-0 so it won't grow beyond its width 16. Div B has flex-grow (equivalent to flex-grow-1) so it will grow to fill leftover space.<div class="flex w-40"> <div class="flex-shrink-0 w-24 bg-green-400">X</div> <div class="flex-shrink w-24 bg-yellow-400">Y</div> </div>
flex-shrink-0, so it cannot shrink below 24. Second div has default shrink, so it tries to shrink but can't reduce enough to fit container.Pass the test and this pattern moves unknown