<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

FlexBox

A simple, unstyled container that understands CSS flex layout without the need for adding any custom CSS.
Info:

FlexBox is only available in the React API for SWAN.

Use FlexBox...

  • To layout content to best organize and fill the available space.
  • To align elements within a container with a specific direction.

Don't use FlexBox...

  • To layout all page content. Use Grid instead.
  • To layout components such as Cards or Standard Tiles. Use Grid instead.
  • To layout form fields. Use Form instead.

The preview has been updated.

Justify Content

Use justifyContent to align items along the primary axis, which is the x-axis by default.

The preview has been updated.

Align Items

Use alignItems to align items along the secondary axis, which is the y-axis by default.

The preview has been updated.

Flex Wrap

Use flexWrap to control whether the items in the FlexBox should wrap to the next line or not.

The preview has been updated.

Flex Direction

Use flexDirection to control whether the items in the FlexBox are laid out in a row or column; this also switches the primary and secondary axis.

The preview has been updated.

Gap

Use gap to put a gutter between the items in the FlexBox. This accepts one of the SWAN standard spacing units as values, 1-13. Note that this controls the inline gap property in the style attribute, so you cannot set the gap via style.

The preview has been updated.

Stack/Inline

Use FlexBox to emulate the functionality of these Emu components:

  • For Stack, use a FlexBox with flexDirection="column", plus a gap property to put a gutter between the children.
  • For Inline, SWAN usually uses the Grid component instead for horizontal layout, to provide the site-standard spacing between the columns and to create visual harmony from page to page. However, for smaller spaces or unusual layouts, use a FlexBox with with flexDirection="row" and a gap.

Props

FlexBox
This component is implemented using the <div /> as the root element. You can utilize the native attributes supported by <div /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
alignItems"center" | "end" | "start" | "inherit" | "initial" | "revert" | "unset" | "stretch" | "flex-end" | "flex-start" | "baseline" | nullfalse
The CSS align-items property sets the align-self value on all direct children as a group. In Flexbox, it controls the alignment of items on the Cross Axis. In Grid Layout, it controls the alignment of items on the Block Axis within their grid area. One of: "stretch", "center", "start", "end", "flex-start", "flex-end", "baseline", "inherit", "initial", "revert", "unset".
null
flexWrap"wrap" | "inherit" | "initial" | "revert" | "unset" | "nowrap" | "wrap-reverse" | nullfalse
The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked. One of: "nowrap", "wrap", "wrap-reverse", "inherit", "initial", "revert", "unset".
null
flexDirection"row" | "inherit" | "initial" | "revert" | "unset" | "column" | "column-reverse" | "row-reverse" | nullfalse
The flex-direction CSS property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed). One of: "row", "row-reverse", "column", "column-reverse", "inherit", "initial", "revert", "unset".
null
justifyContent"center" | "end" | "start" | "inherit" | "left" | "right" | "normal" | "initial" | "revert" | "unset" | "space-around" | "space-between" | "space-evenly" | "stretch" | "flex-end" | "flex-start" | nullfalse
The CSS justify-content property defines how the browser distributes space between and around content items along the main-axis of a flex container, and the inline axis of a grid container. One of: "stretch", "center", "start", "end", "flex-start", "flex-end", "left", "right", "normal", "space-between", "space-around", "space-evenly", "inherit", "initial", "revert", "unset".
null
gap0 | 1 | 2 | "0" | "1" | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "between-sections" | "between-subsections" | "between-actions" | "to-actions" | nullfalse
The gap property places a uniform gap (gutter) between the flex container's children.
null
Was this page useful?

Thanks for your feedback!

Feel free to include your name if you wish to have a follow up conversation.


Published: Jan 7, 2022Last updated: Sep 3, 2024