Skip to Content
文档

弹性

用于管理弹性布局

Source

用法

¥Usage

import { Flex, Spacer } from "@chakra-ui/react"
<Flex>
  <div />
  <div />
</Flex>

示例

¥Examples

方向

¥Direction

使用 directionflexDirection prop 更改 flex 的方向

¥Use the direction or flexDirection prop to change the direction of the flex

对齐

¥Align

使用 alignalignItems prop 使子元素沿横轴对齐。

¥Use the align or alignItems prop to align the children along the cross axis.

对齐

¥Justify

使用 justifyjustifyContent prop 使子元素沿主轴对齐。

¥Use the justify or justifyContent prop to align the children along the main axis.

flex-start
center
flex-end
space-between

顺序

¥Order

使用 order 属性更改子项的顺序。

¥Use the order prop to change the order of the children.

1
2
3

自动边距

¥Auto Margin

对弹性项目应用外边距,使其远离其兄弟元素。

¥Apply margin to a flex item to push it away from its siblings.

间隔

¥Spacer

使用 Spacer 组件在弹性项目之间创建弹性空间。它会扩展以填充所有可用空间,并将项目推到两端。

¥Use the Spacer component to create flexible space between flex items. It will expand to fill all available space, pushing items to opposite ends.

Box 1
Box 2

换行

¥Wrap

使用 wrapflexWrap 属性在子元素溢出父元素时封装子元素。

¥Use the wrap or flexWrap prop to wrap the children when they overflow the parent.

属性

¥Props

PropDefaultType
align
SystemStyleObject['alignItems'] | undefined

justify
SystemStyleObject['justifyContent'] | undefined

wrap
SystemStyleObject['flexWrap'] | undefined

direction
SystemStyleObject['flexDirection'] | undefined

basis
SystemStyleObject['flexBasis'] | undefined

grow
SystemStyleObject['flexGrow'] | undefined

shrink
SystemStyleObject['flexShrink'] | undefined

inline
boolean | undefined

as
React.ElementType

The underlying element to render.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.

Previous

容器

Next

浮动