Find the exact width where a flex row wraps
Admin ·
The visible width of a flex container includes more than its items. Use the Card row example to see how gaps and padding determine the point at which a three-card row wraps.
Reproduce the wrap from 408 to 407 pixels
Load Card row. Leave each basis at 120 pixels, Gap and Padding at 12 pixels, and Wrap mode at wrap. Set Preview width to 408 pixels and Preview height to 176 pixels. Lead, Support and Links fit on one line.
The three bases use 360 pixels. Two gaps add 24 pixels and both horizontal padding edges add another 24 pixels. At 407 pixels, Links moves down beside the left edge.
Compare wrapping with shrinking the same cards
Keep 407 pixels and change Wrap mode to nowrap. Flex shrink is 1 on each card, so the three cards remain on one line and share the one-pixel shortage.
Try an Item order of -1 on Links. It appears first in the preview while it remains third in the HTML. When the reorder changes meaning or intended keyboard order, move the element in the markup.
W3C CSS Flexible Box Layout, components of flexibilityW3C CSS Flexible Box Layout, reordering and accessibility
Check the CSS and HTML together
Download flex-layout.css and flex-layout.html. The HTML uses flex-layout on the parent and a flex-item class plus a numbered class on each direct child. The CSS uses those numbered classes for item overrides.
To compare the result in your project, give the parent 408 pixels of available outer width and ensure no other rule overrides the sizing, gap or padding. The generated CSS includes border-box sizing and does not set the workspace's preview width.
W3C CSS Flexible Box Layout, flex linesW3C CSS Flexible Box Layout, components of flexibility
Common questions
Why does changing line alignment appear to do nothing?
Line alignment needs a multi-line flex container. Try the wrapped 407-pixel example with spare height and compare center with stretch.
Why do my project's cards wrap sooner?
Compare the parent's available width and padding, the gap and each item's main-axis size. Additional sizing rules or intrinsic minimum sizes can change how much space is needed.