使用高级 Chakra UI 组件更快地构建 💎

了解更多
跳到内容
文档演练场指南博客
赞助商

标题

用于渲染语义化的 HTML 标题元素。

敏捷的棕狐狸跃过懒惰的狗

用法

import { Heading } from "@chakra-ui/react"
<Heading>I'm a Heading</Heading>

示例

尺寸

使用 size prop 更改标题组件的尺寸。

标题 (sm)

标题 (md)

标题 (lg)

标题 (xl)

标题 (2xl)

标题 (3xl)

标题 (4xl)

标题 (5xl)

标题 (6xl)

高亮

Heading 组件与 Highlight 组件组合,以高亮文本。

快速创建可访问的 React 应用程序速度更快

Chakra UI 是一个简单、模块化且易于访问的组件库,为您提供所需的构建块。

作为另一个元素

使用 as prop 将标题渲染为另一个 HTML 元素。

级别 1

级别 2

级别 3

字重

使用 fontWeight prop 更改标题组件的字重。

正常

中等

半粗

粗体

组合

使用 Heading 组件组合其他组件。

适用于商店的现代化支付

PayMe 帮助初创公司在世界任何地方向任何人收款

自定义

要覆盖 fontSize,我们建议使用 textStyle prop,因为它也考虑了行高和字间距。

基础样式

这是一个自定义 Heading 组件的示例。

provider.tsx

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

const headingRecipe = defineRecipe({
  base: {
    fontWeight: "normal",
    textStyle: "4xl",
  },
})

const system = createSystem(defaultConfig, {
  theme: {
    recipes: { heading: headingRecipe },
  },
})

自定义尺寸

更新 variants.size 属性以创建自定义尺寸。

provider.tsx

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

const headingRecipe = defineRecipe({
  variants: {
    size: {
      custom: {
        fontSize: "100px",
        lineHeight: "100px",
        letterSpacing: "-2px",
      },
    },
  },
})

const system = createSystem(defaultConfig, {
  theme: {
    recipes: { heading: headingRecipe },
  },
})

然后,使用 custom 变体来创建自定义尺寸。

<Heading size="custom">I'm a custom size</Heading>

属性

属性默认类型
colorPalette 'gray'
'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'

组件的调色板

size 'xl'
'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | '7xl'

组件的尺寸

上一个

强调

下一个

高亮