1. 排版
  2. 文本缩进

Quick reference

属性
indent-0text-indent: 0px;
indent-pxtext-indent: 1px;
indent-0.5text-indent: 0.125rem; /* 2px */
indent-1text-indent: 0.25rem; /* 4px */
indent-1.5text-indent: 0.375rem; /* 6px */
indent-2text-indent: 0.5rem; /* 8px */
indent-2.5text-indent: 0.625rem; /* 10px */
indent-3text-indent: 0.75rem; /* 12px */
indent-3.5text-indent: 0.875rem; /* 14px */
indent-4text-indent: 1rem; /* 16px */
indent-5text-indent: 1.25rem; /* 20px */
indent-6text-indent: 1.5rem; /* 24px */
indent-7text-indent: 1.75rem; /* 28px */
indent-8text-indent: 2rem; /* 32px */
indent-9text-indent: 2.25rem; /* 36px */
indent-10text-indent: 2.5rem; /* 40px */
indent-11text-indent: 2.75rem; /* 44px */
indent-12text-indent: 3rem; /* 48px */
indent-14text-indent: 3.5rem; /* 56px */
indent-16text-indent: 4rem; /* 64px */
indent-20text-indent: 5rem; /* 80px */
indent-24text-indent: 6rem; /* 96px */
indent-28text-indent: 7rem; /* 112px */
indent-32text-indent: 8rem; /* 128px */
indent-36text-indent: 9rem; /* 144px */
indent-40text-indent: 10rem; /* 160px */
indent-44text-indent: 11rem; /* 176px */
indent-48text-indent: 12rem; /* 192px */
indent-52text-indent: 13rem; /* 208px */
indent-56text-indent: 14rem; /* 224px */
indent-60text-indent: 15rem; /* 240px */
indent-64text-indent: 16rem; /* 256px */
indent-72text-indent: 18rem; /* 288px */
indent-80text-indent: 20rem; /* 320px */
indent-96text-indent: 24rem; /* 384px */

基本用法

¥Basic usage

添加文本缩进

¥Adding a text indent

使用 indent-* 工具设置块中文本前显示的空白空间(缩进)量。

¥Use the indent-* utilities to set the amount of empty space (indentation) that’s shown before text in a block.

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. 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 <em>was</em> a marine biologist.
</p>

使用负值

¥Using negative values

要使用负文本缩进值,请在类名称前加上破折号以将其转换为负值。

¥To use a negative text indent value, prefix the class name with a dash to convert it to a negative value.

<div class="-indent-8">
  So I started to walk into the water. I won't lie to...
</div>

有条件地应用

悬停、聚焦和其他状态

Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:indent-8 仅在 hover 时应用 indent-8 工具。

<div class="indent-4 hover:indent-8">
  <!-- ... -->
</div>

有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。

断点和媒体查询

你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:indent-8 仅在中等屏幕尺寸及以上时应用 indent-8 工具。

<div class="indent-4 md:indent-8">
  <!-- ... -->
</div>

要了解更多信息,请查看有关 响应式设计暗黑模式、以及 其他媒体查询修饰符 的文档。


使用自定义值

¥Using custom values

自定义主题

¥Customizing your theme

默认文本缩进比例基于 默认间距比例。你可以通过编辑 tailwind.config.js 文件中的 theme.spacingtheme.extend.spacing 来自定义间距比例。

¥The default text indent scale is based on the default spacing scale. You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      spacing: {
        '128': '32rem',
      }
    }
  }
}

或者,你可以通过编辑 tailwind.config.js 文件中的 theme.textIndenttheme.extend.textIndent 来自定义文本缩进比例。

¥Alternatively, you can customize just the text indent scale by editing theme.textIndent or theme.extend.textIndent in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      textIndent: {
        '128': '32rem',
      }
    }
  }
}

主题定制 文档中了解有关自定义默认主题的更多信息。

¥Learn more about customizing the default theme in the theme customization documentation.

任意值

¥Arbitrary values

如果你需要使用一次性的 text-indent 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。

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

任意值 文档中了解有关任意值支持的更多信息。