1. 字体
  2. text-indent

字体

文本缩进

用于控制块级文本前空白空间大小的工具类。

ClassStyles
indent-<number>
text-indent: calc(var(--spacing) * <number>)
-indent-<number>
text-indent: calc(var(--spacing) * -<number>)
indent-px
text-indent: 1px;
-indent-px
text-indent: -1px;
indent-(<custom-property>)
text-indent: var(<custom-property>);
indent-[<value>]
text-indent: <value>;

示例

基础示例

使用 indent-<number> 工具类(如 indent-2indent-8)来设置块级文本前的空白空间(缩进)大小:

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<p class="indent-8">So I started to walk into the water...</p>

使用负值

要使用负的文本缩进值,在类名前添加破折号将其转换为负值:

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<p class="-indent-8">So I started to walk into the water...</p>

使用自定义值

Use the indent-[<value>] syntax to set the 文本缩进 based on a completely custom value:

<p class="indent-[50%] ...">  Lorem ipsum dolor sit amet...</p>

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

<p class="indent-(--my-indentation) ...">  Lorem ipsum dolor sit amet...</p>

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

响应式设计

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

<p class="indent-4 md:indent-8 ...">  Lorem ipsum dolor sit amet...</p>

Learn more about using variants in the variants documentation.

Copyright © 2025 Tailwind Labs Inc.·Trademark Policy