Photo by Zdeněk Macháček on Unsplash
Flex
Natura11y's flexbox utilities provide options for creating one-dimensional layouts. Some flexbox utilities deal with horizontal and vertical alignment. These utilities work alongside the navigation, grid, and backdrop components.
Flex Direction Utilities
The flex direction utilities (Figure 1) create the flex container. They define the main axis: row or column, along with direction: normal or reverse. Further, they set the flex-wrap property to wrap.
Need a flex row that doesn't wrap? Replace .flex-row
with .display-flex
(from the display utilities).
Breakpoint Modifiers
Flex direction utilities accept breakpoint modifiers.
With the HTML in Figure 2, the flex container starts with the column direction. It then changes to the row direction at the large breakpoint.
Flex Grow Utilities
The Flex grow utilities set the grow factor of a flex item along the flex container's main axis. The default grow value of a flex item is 0.
With .flex-grow-1
, applied to a flex item, it will grow to fill any available space.
Flex Shrink Utilities
The Flex shrink utilities (e.g., .flex-shrink-{x}
) set the shrink factor of a flex item, where x equals 0, 1, or 2.These three decimals represent the amount which the flex item shrinks.
With a flex shrink value of 0, a flex item will not shrink as it's flex container gets smaller. With a shrink value of 1, the flex item will shrink, but no smaller than it’s content. Finally, a flex item with a flex shrink value of 2 will shrink smaller than it’s content.
With the examples below, .flex-shrink-1
applied to the first flex item allows it to shrink along it's main axis.
Justify Content Utilites
The justify content utilites (Figure 3) align items along the main-axis of their flex container.
Breakpoint Modifiers
Justify content utilities accept breakpoint modifiers.
With the HTML in Figure 4. The flex container changes it's justification to end at the large breakpoint.
Align Content Utilites
The align content utilites distribute the space between and around items along the flex container's cross-axis.
Breakpoint Modifiers
Align content utilities accept breakpoint modifiers.
With the HTML in Figure 6. The flex container starts its alignment with start then changes to end at the large breakpoint.