Back to Ant Design

Flex

components/flex/index.en-US.md

6.3.72.3 KB
Original Source

When To Use

  • Good for setting spacing between elements.
  • Suitable for setting various horizontal and vertical alignments.

Difference with Space component

  • Space is used to set the spacing between inline elements. It will add a wrapper element for each child element for inline alignment. Suitable for equidistant arrangement of multiple child elements in rows and columns.
  • Flex is used to set the layout of block-level elements. It does not add a wrapper element. Suitable for layout of child elements in vertical or horizontal direction, and provides more flexibility and control.

Examples

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/align.tsx">align</code> <code src="./demo/gap.tsx">gap</code> <code src="./demo/wrap.tsx">Wrap</code> <code src="./demo/combination.tsx">combination</code> <code src="./demo/debug.tsx" debug>debug</code>

API

This component is available since [email protected]. The default behavior of Flex in horizontal mode is to align upward, In vertical mode, aligns the stretch, You can adjust this via properties.

Common props ref:Common props

PropertyDescriptionTypeDefaultVersion
verticalIs direction of the flex vertical, use flex-direction: columnbooleanfalse
wrapSet whether the element is displayed in a single line or in multiple linesflex-wrap | booleannowrapboolean: 5.17.0
justifySets the alignment of elements in the direction of the main axisjustify-contentnormal
alignSets the alignment of elements in the direction of the cross axisalign-itemsnormal
flexflex CSS shorthand propertiesflexnormal
gapSets the gap between gridssmall | medium | large | string | number-
componentcustom element typeReact.ComponentTypediv
orientationdirection of the flexhorizontal | verticalhorizontal-

Design Token

<ComponentTokenTable component="Flex"></ComponentTokenTable>