Tailwind CSS on GitHub

行高

用于控制元素的前行距(行高)的功能类。

Default class reference

Class
Properties
leading-3line-height: .75rem;
leading-4line-height: 1rem;
leading-5line-height: 1.25rem;
leading-6line-height: 1.5rem;
leading-7line-height: 1.75rem;
leading-8line-height: 2rem;
leading-9line-height: 2.25rem;
leading-10line-height: 2.5rem;
leading-noneline-height: 1;
leading-tightline-height: 1.25;
leading-snugline-height: 1.375;
leading-normalline-height: 1.5;
leading-relaxedline-height: 1.625;
leading-looseline-height: 2;

相对行高

使用 leading-noneleading-tightleading-snugleading-normalleading-relaxedleading-loose 等功能类,根据元素当前的字体大小,给它一个相对的行高。

.leading-none

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-tight

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-snug

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-normal

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-relaxed

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-loose

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

<p class="leading-none ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-tight ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-snug ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-normal ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-relaxed ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-loose ...">Lorem ipsum dolor sit amet ...</p>

固定行高

使用 leading-{size} 功能类给一个元素一个固定的行高,而不管当前的字体大小。当您需要非常精确地控制一个元素的最终大小时,这些功能类非常有用。

.leading-3

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-4

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-5

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-6

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-7

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-8

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-9

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

.leading-10

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda, quia temporibus eveniet a libero incidunt suscipit laborum, rerum accusantium modi quidem, ipsam illum quis sed voluptatum quae eum fugit earum.

<p class="leading-3 ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-4 ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-5 ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-6 ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-7 ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-8 ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-9 ...">Lorem ipsum dolor sit amet ...</p>
<p class="leading-10 ...">Lorem ipsum dolor sit amet ...</p>

响应式

要在特定的断点处控制元素的行高,请在任何现有的行高功能类前添加 {screen}: 前缀。例如,使用 md:leading-loose 来仅在中等大小及以上的屏幕应用 leading-loose 功能类。

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

关于 Tailwind 的响应式设计功能的更多信息,请查看 响应式设计 文档。

定制

默认情况下,Tailwind 提供了六个相对的和八个固定的 line-height 功能类。您可以通过定制您的 Tailwind 主题配置的 lineHeight 部分来改变、添加或删除这些功能类。

  // tailwind.config.js
  module.exports = {
    theme: {
      extend: {
        lineHeight: {
+         'extra-loose': '2.5',
+         '12': '3rem',
        }
      }
    }
  }

变体

默认情况下, 针对 line height 功能类,只生成 responsive 变体。

您可以通过修改您的 tailwind.config.js 文件中的 variants 部分中的 lineHeight 属性来控制为 line height 功能生成哪些变体。

例如,这个配置将生成 hover and focus 变体:

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       lineHeight: ['hover', 'focus'],
      }
    }
  }

禁用

如果您不打算在您的项目中使用 line height 功能,您可以通过在配置文件的 corePlugins 部分将 lineHeight property to false in the corePlugins section of your config file:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     lineHeight: false,
    }
  }