Flex
Overview
The Flex
component extends the Box
utility component and provides a CSS flexbox container alongside flexbox properties.
When to use:
- Want to lay a collection of items out in one direction or another.
- Want to control the dimensions of the items in that one dimension, or control the spacing between items.
- Justify or vertically align items as needed.
- Mostly used for simple one dimensional layouts.
Implementation
Edit the code below to see your changes live!
<Flex alignContent="stretch" alignItems="stretch" flexDirection="row" flexWrap="nowrap" justifyContent="flex-start" > <FlexItem alignSelf="auto" flexBasis="auto" flexGrow={0} flexOrder={0} flexShrink={1} > <ExampleBox>Item 1</ExampleBox> </FlexItem> <FlexItem alignSelf="auto" flexBasis="auto" flexGrow={0} flexOrder={0} flexShrink={1} > <ExampleBox>Item 2</ExampleBox> </FlexItem> <FlexItem alignSelf="auto" flexBasis="auto" flexGrow={0} flexOrder={0} flexShrink={1} > <ExampleBox>Item 3</ExampleBox> </FlexItem> <FlexItem alignSelf="auto" flexBasis="auto" flexGrow={0} flexOrder={0} flexShrink={1} > <ExampleBox>Item 4</ExampleBox> </FlexItem> </Flex>
Props
Prop name | Type | Default | Description |
---|---|---|---|
alignContent | stretch | center | flex-start | flex-end | space-between | space-around | stretch | Modifies the behavior of the |
alignItems | normal | stretch | center | flex-start | flex-end | baseline | stretch | Specifies the default alignment for items in a flex container. Same as the |
flexColumnGap | string |
| Sets the size of the gap between flex columns. Same as the |
flexDirection | row | column | row-reverse | column-reverse | row | Determines the direction of flex items. Same as the |
flexGap | string |
| Controls the spacing between flex items. Same as the |
flexRowGap | string |
| Sets the size of the gap between flex rows. Same as the |
justifyContent | center | flex-start | flex-end | left | right | normal | space-between | space-around | space-evenly | stretch | flex-start | Modifies the behavior of the |
flexWrap | nowrap | wrap | wrap-reverse | nowrap | Controls whether flex items should wrap or not. Same as the |
Props ending with * are required
Inherited
Box Props
Display Props
Margin Props
Padding Props
Do's and Don'ts
Do |
---|
Use Flex when focusing on 1-dimensional or content flow. |
Use FlexItem when children need specific flex properties. |
Use CSS-Tricks complete guide to flexbox. |
Don't |
---|
Don’t use Flex when focusing on 2-dimensional flow. Use Grid instead. |
Don't use FlexItem if children don't have specific flex properties. |