You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>A flexbox has two axes, which are treated differently by the space distribute algorithm: the <b>layout axis</b>, which is the axis along which the flexbox grows as you add more children, and the <b>transverse axis</b>, which is the perpendicular axis.</p>
581
+
582
+
<imgalt="In a horizontal flexbox, the layout axis is horizontal, while the transverse axis is vertical.">
583
+
584
+
<p>The layout axis is more interesting, as there are more places where things can potentially flex. As such, there are more controls for specifying how to distribute free space in this axis: the 'width' or 'height' property starts things off, modified by the 'flex' property; the 'margin' property gives individual control over spacing between flexbox children; and the 'flex-pack' property gives a more flexbox-global level of control over the between-children spacing.</p>
585
+
586
+
<p>In general terms, determining where to allocate free space in the layout axis starts by determining just how much free space there is. All the non-flexible lengths, and the preferred sizes of all the flexible widths or heights, are subtracted from the total width or height of the flexbox. If a positive length is left over, this is split up among all the flexible lengths according to their flexibility. Flexible margins automatically have a flexibility of 1, while widths or heights have their flexibility specified by the 'flex-grow' property.</p>
587
+
588
+
<divclass=example>
589
+
<p>Three boxes, all with a preferred size of 0, will end up with sizes exactly proportional to their flex-grow values.</p>
590
+
<imgalt="">
591
+
</div>
592
+
<divclass=example>
593
+
<p>If the three boxes have different preferred sizes, then they'll split the free space proportionately, but their final sizes won't be exactly proportional.</p>
594
+
<imgalt="">
595
+
</div>
596
+
<divclass=example>
597
+
<p>Margins can also participate in flex calculations. They have a preferred size of 0, and a flexibility of 1.</p>
598
+
<imgalt="">
599
+
</div>
600
+
601
+
<p>If none of the lengths are flexible, or if all the flexible widths or height have reached their maximum size (if 'max-width' or 'max-height' properties are in effect), then any leftover space is distributed according to the 'flex-pack' property between the margins of the flexbox children.</p>
602
+
603
+
<divclass=example>
604
+
<p>If the flexbox is small enough, then the flexible child can absorb all the space...</p>
605
+
<img>
606
+
<p>...but if it gets large enough, there'll be extra space left over for 'flex-pack' to distribute.</p>
607
+
<img>
608
+
</div>
609
+
610
+
<p>If the original calculation of how much free space was left gave a negative length (that is, if the preferred sizes of all the flexbox children sum to a larger length than the width or height of the flexbox), then flexible margins get set to 0, 'flex-pack' has no effect, and flexbox children with a non-zero 'flex-shrink' value split the responsibility for shrinking between themselves proportionally. Just like when they grow, their size starts from the preferred size, then combines that with the proportional share of (negative) space.</p>
611
+
612
+
<divclass=example>
613
+
<p>When the children are too wide, the shrinkable elements reduce their size to fit...</p>
614
+
<img>
615
+
<p>...but if they all reach their minimum size, they just overflow.</p>
0 commit comments