Skip to Content
文档

尺寸

了解如何在 Chakra UI 中自定义尺寸

info

请先阅读 overview 组件,了解如何正确自定义样式引擎并确保类型安全。

¥Please read the overview first to learn how to properly customize the styling engine, and get type safety.

示例

¥Example

以下是如何在 Chakra UI 中自定义大小的示例。

¥Here's an example of how to customize sizes in Chakra UI.

theme.ts

import { createSystem, defaultConfig, defineConfig } from "@chakra-ui/react"

const customConfig = defineConfig({
  theme: {
    tokens: {
      sizes: {
        "1/7": { value: "14.285%" },
        "2/7": { value: "28.571%" },
        "3/7": { value: "42.857%" },
      },
    },
  },
})

export const system = createSystem(defaultConfig, customConfig)

用法

¥Usage

将所有与尺寸相关的属性(例如 widthheightminWidthminHeightmaxWidthmaxHeight 等)的值设置为 sizes 令牌。

¥Set the value of any size related properties, like width, height, minWidth, minHeight, maxWidth, maxHeight, etc. to the sizes token.

<Box width="1/7" height="2/7" />

Previous

秘诀

Next

间距