排版
line-height
用于控制元素行距或行高的工具。
| 类 | 样式 |
|---|---|
text-<size>/<number> | font-size: <size>;
line-height: calc(var(--spacing) * <number>); |
text-<size>/(<custom-property>) | font-size: <size>;
line-height: var(<custom-property>); |
text-<size>/[<value>] | font-size: <size>;
line-height: <value>; |
leading-none | line-height: 1; |
leading-<number> | line-height: calc(var(--spacing) * <number>); |
leading-(<custom-property>) | line-height: var(<custom-property>); |
leading-[<value>] | line-height: <value>; |
示例(Examples)
基本示例(Basic example)
使用字体大小工具类如 text-sm/6 和 text-lg/7 来同时设置元素的字体大小和行高:
🌐 Use font size utilities like text-sm/6 and text-lg/7 to set the font size and line-height of an element at the same time:
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.
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.
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="text-base/6 ...">So I started to walk into the water...</p><p class="text-base/7 ...">So I started to walk into the water...</p><p class="text-base/8 ...">So I started to walk into the water...</p>每个字体大小工具在未提供行高时也会设置默认行高。你可以在字体大小文档中了解有关这些值以及如何自定义它们的更多信息。
🌐 Each font size utility also sets a default line height when one isn't provided. You can learn more about these values and how to customize them in the font-size documentation.
单独设置(Setting independently)
使用 leading-<number> 工具,如 leading-6 和 leading-7,来独立于字体大小设置元素的行高:
🌐 Use leading-<number> utilities like leading-6 and leading-7 to set the line height of an element independent of the font-size:
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.
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.
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="text-sm leading-6">So I started to walk into the water...</p><p class="text-sm leading-7">So I started to walk into the water...</p><p class="text-sm leading-8">So I started to walk into the water...</p>删除前导(Removing the leading)
使用 leading-none 工具将元素的行高设置为与其字体大小相等:
🌐 Use the leading-none utility to set the line height of an element equal to its font size:
The quick brown fox jumps over the lazy dog.
<p class="text-2xl leading-none ...">The quick brown fox...</p>使用自定义值(Using a custom value)
使用 leading-[<value>] 语法 根据完全自定义的值设置 line height:
<p class="leading-[1.5] ..."> Lorem ipsum dolor sit amet...</p>对于 CSS 变量,还可以使用 leading-(<custom-property>) 语法:
<p class="leading-(--my-line-height) ..."> Lorem ipsum dolor sit amet...</p>这只是简写,用于 leading-[var(<custom-property>)] 它会自动为你添加 var() 函数。
响应式设计(Responsive design)
在 line-height 工具前面使用断点变体如 md: 仅在 medium 屏幕尺寸及以上时应用工具:
<p class="leading-5 md:leading-6 ..."> Lorem ipsum dolor sit amet...</p>请参阅 变体文档 详细了解如何使用变体。
自定义主题(Customizing your theme)
该 leading-<number> 工具由 --spacing 主题变量驱动,可以在你自己的主题中进行自定义:
@theme { --spacing: 1px; }在主题变量文档中了解有关自定义间距比例的更多信息。