1. Typography
  2. text-indent

Typography

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 text indentation based on a completely custom value:

<p class="indent-[50%] ...">  <!-- ... --></p>

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

<p class="indent-(--my-indentation) ...">  <!-- ... --></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 ...">  <!-- ... --></p>

Learn more about using variants in the variants documentation.

版权所有 © 2025 Tailwind Labs Inc.·商标政策