1. 排版
  2. 行高

排版

行高

控制元素行距或行高的工具类。

ClassStyles
text-<size>/<number>
font-size: <size>; line-height: calc(var(--spacing) * <number>);
text-<size>/(<custom-property>)
font-size: <size>; line-height: var(<custom-property>);
text-<size>/[<value>]
font-size: <size>; line-height: <value>;
leading-none
line-height: 1;
leading-<number>
line-height: calc(var(--spacing) * <number>)
leading-(<custom-property>)
line-height: var(<custom-property>);
leading-[<value>]
line-height: <value>;

示例

基本示例

使用字体大小工具类如 text-sm/6text-lg/7 同时设置元素的字体大小和行高:

text-sm/6

所以我开始走进水中。我不会对你们撒谎,伙计们,我很害怕。但我坚持下去了,当我穿过海浪时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你,杰瑞,在那一刻,我 就是 一名海洋生物学家。

text-sm/7

所以我开始走进水中。我不会对你们撒谎,伙计们,我很害怕。但我坚持下去了,当我穿过海浪时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你,杰瑞,在那一刻,我 就是 一名海洋生物学家。

text-sm/8

所以我开始走进水中。我不会对你们撒谎,伙计们,我很害怕。但我坚持下去了,当我穿过海浪时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你,杰瑞,在那一刻,我 就是 一名海洋生物学家。

<p class="text-base/6 ...">所以我开始走进水中...</p><p class="text-base/7 ...">所以我开始走进水中...</p><p class="text-base/8 ...">所以我开始走进水中...</p>

每个字体大小工具类在没有提供行高时也会设置一个默认的行高。有关这些值及如何自定义它们的更多信息,请查看 字体大小文档

独立设置

使用 leading-<number> 工具类如 leading-6leading-7 来独立于字体大小设置元素的行高:

leading-6

所以我开始走进水中。我不会对你们撒谎,伙计们,我很害怕。但我坚持下去了,当我穿过海浪时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你,杰瑞,在那一刻,我 就是 一名海洋生物学家。

leading-7

所以我开始走进水中。我不会对你们撒谎,伙计们,我很害怕。但我坚持下去了,当我穿过海浪时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你,杰瑞,在那一刻,我 就是 一名海洋生物学家。

leading-8

所以我开始走进水中。我不会对你们撒谎,伙计们,我很害怕。但我坚持下去了,当我穿过海浪时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你,杰瑞,在那一刻,我 就是 一名海洋生物学家。

<p class="text-sm leading-6">所以我开始走进水中...</p><p class="text-sm leading-7">所以我开始走进水中...</p><p class="text-sm leading-8">所以我开始走进水中...</p>

移除行高

使用 leading-none 工具类将元素的行高设置为与其字体大小相等:

机敏的棕色狐狸跳过懒狗。

<p class="text-2xl leading-none ...">机敏的棕色狐狸...</p>

使用自定义值

Use the leading-[<value>] syntax to set the 行高 based on a completely custom value:

<p class="leading-[1.5] ...">  Lorem ipsum dolor sit amet...</p>

For CSS variables, you can also use the leading-(<custom-property>) syntax:

<p class="leading-(--my-line-height) ...">  Lorem ipsum dolor sit amet...</p>

This is just a shorthand for leading-[var(<custom-property>)] that adds the var() function for you automatically.

响应式设计

Prefix a line-height utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<p class="leading-5 md:leading-6 ...">  Lorem ipsum dolor sit amet...</p>

Learn more about using variants in the variants documentation.

自定义主题

The leading-<number> utilities are driven by the --spacing theme variable, which can be customized in your own theme:

@theme {  --spacing: 1px; }

Learn more about customizing the spacing scale in the theme variable documentation.