Flex
Flex utilities shape a flex container and its children: the direction of the
main axis, whether items wrap, and how they grow or shrink. Set display first
with d-flex, flex, or d-inline-flex.
Alignment and spacing are separate families: see Alignment for
justify-* and align-*, and Gap for gap-*.
Direction and wrapping
Section titled “Direction and wrapping”| Class | flex-direction |
|---|---|
flex-row |
row |
flex-row-reverse |
row-reverse |
flex-column |
column |
flex-column-reverse |
column-reverse |
| Class | flex-wrap |
|---|---|
flex-nowrap |
nowrap |
flex-wrap |
wrap |
flex-wrap-reverse |
wrap-reverse |
The base wrapping classes are compact-only; their responsive forms use the long
pattern: flex-md-wrap, flex-lg-nowrap, flex-xl-wrap-reverse.
<div class="d-flex flex-column flex-md-row flex-wrap gap-3">…</div>Responsive: flex-sm-row, flex-md-column, flex-lg-wrap, and so on.
These classes are in the separate responsive module: import
nightcss/utilities/responsive after the base bundle, or use
nightcss/full.
Growth and shrinking
Section titled “Growth and shrinking”| Class | Effect |
|---|---|
flex-grow-0, flex-grow-1 |
flex-grow |
flex-shrink-0, flex-shrink-1 |
flex-shrink |
flex-1 |
flex: 1 1 0% |
flex-auto |
flex: 1 1 auto |
flex-none |
flex: none |
flex-1, flex-auto, and flex-none are compact-only. The generated growth
classes have responsive forms written as flex-md-grow-1 and flex-md-shrink-0.
<div class="d-flex gap-2"> <div class="flex-grow-1">Takes the remaining space</div> <div class="flex-shrink-0">Stays its own width</div></div>Shortcut
Section titled “Shortcut”flex-center is a one-class flex container centered on both axes:
<div class="flex-center" style="min-block-size: 8rem">Centered</div>Responsive: flex-sm-center … flex-2xl-center.