Skip to content
全部文档

text-indent

用于控制块级文本前空白距离的工具类。

快速参考

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

示例

基础示例

使用 indent-2indent-8indent-<number> 工具类,设置块级文本前显示的空白(缩进)量:

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.

html
<!-- [!code classes:indent-8] -->
<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.

html
<!-- [!code classes:-indent-8] -->
<p class="-indent-8">So I started to walk into the water...</p>

使用自定义值

使用 indent-[<value>] 等工具类,根据完全自定义的值设置文本缩进:

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

对于 CSS 变量,也可以使用 indent-(<custom-property>) 语法:

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

这只是 indent-[var(<custom-property>)] 的简写,会自动为你加上 var() 函数。

响应式设计

使用 md: 等断点变体作为 text-indent 工具类的前缀,即可只在中等屏幕尺寸及以上应用该工具类:

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

更多关于变体的用法,请参阅变体文档

文档译文以 MIT 协议授权;原文版权归 Tailwind Labs。湘ICP备2026005453号-2