Flex
Build flexible layouts using CSS Flexbox
Use the Flex
component to arrange and align content dynamically within a container using CSS Flexbox. To use the Flex
component, make sure you don’t have the includeUtilities
rule disabled in your setup
mixin (this rule is enabled by default):
Flex
component. You can read more in the Layout section. Simply pass your elements or components inside the Flex
component to display them in a flex container. By default, the element will be rendered as a div
. This can be changed using the element
prop:
Gap
The gap between flex items is set to 20px by default. To change this, use the gap
prop with one of the following values:
Prop value | Default value |
---|---|
none | 0 |
xxs | 2px |
xs | 5px |
sm | 10px |
md | 15px |
default | 20px |
lg | 25px |
xl | 30px |
xl2 | 35px |
xl3 | 40px |
xl4 | 45px |
xl5 | 50px |
You can configure your gaps using the webcore.config.scss
configuration file. Read more about how to configure gaps in the CSS configuration documentation.
Direction
To set the direction of your flex container, set the direction
property whose value can be one of row
, column
, row-reverse
, or column-reverse
:
Alignment
To change the horizontal or vertical alignment of your flex items, use the alignment
prop with one or both of the following values:
You can pass a vertical
property to the object in a similar manner to specify the vertical alignment of your items:
Wrap
Similar to the direction
prop, you can set the way elements wrap using the wrap
prop. It accepts the following values which directly correspond with the native CSS value: wrap
, nowrap
, wrap-reverse
.
Responsiveness
The above properties can also be used responsively. Simply pass an object for the prop that you’d like to change based on media queries and define the following props:
Notice that for alignment
, you’ll need to pass an object that can have a horizontal
and vertical
property. All breakpoints are optional, you can create the object as needed.
webcore.config.scss
configuration file. Read more in the CSS Configurations guide to see examples. API
Prop | Default | Purpose |
---|---|---|
element | div | Sets the HTML tag used for the flex container. |
gap | 20px | Sets the gap between flex items. |
alignment | start | Sets the horizontal and vertical alignment of flex items. |
direction | row | Sets the direction of flex items. |
wrap | nowrap | Sets the wrapping of flex items. |
className | - | Pass additional CSS classes for the element. |
Request improvement for this page