Skip to content

Text Underline Offset 文本下划线偏移

控制文本下划线偏移量的实用工具。

ClassProperties

基本用法

设置下划线偏移量

使用 underline-offset-{width} 实用工具来改变文本下划线的偏移量。

underline-offset-1

The quick brown fox jumps over the lazy dog.

underline-offset-2

The quick brown fox jumps over the lazy dog.

underline-offset-4

The quick brown fox jumps over the lazy dog.

underline-offset-8

The quick brown fox jumps over the lazy dog.

html
<p class="underline underline-offset-1 ...">The quick brown fox...</p>
<p class="underline underline-offset-2 ...">The quick brown fox...</p>
<p class="underline underline-offset-4 ...">The quick brown fox...</p>
<p class="underline underline-offset-8 ...">The quick brown fox...</p>

有条件地应用

悬停、焦点和其他状态

Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 hover:underline-offset-4 只在悬停时应用 underline-offset-4 实用程序。

html
<p class="underline hover:underline-offset-4">
  <!-- ... -->
</p>

有关所有可用状态修改器的完整列表,请查看悬停、焦点和其他状态文档。

断点和媒体查询

您还可以使用变体修饰符来针对响应式断点、深色模式、prefers-reduced-motion 等媒体查询进行定位。例如,使用 md:underline-offset-4 仅在中等屏幕尺寸及以上应用 underline-offset-4 实用程序。

html
<p class="underline md:underline-offset-4">
  <!-- ... -->
</p>

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

使用自定义值

定制您的主题

您可以通过编辑您的 tailwind.config.js 文件中的 theme.textUnderlineOffsettheme.extend.textUnderlineOffset 来自定义 underline-offset-{width} 实用程序。

js
module.exports = {
  theme: {
    extend: {
      textUnderlineOffset: {		
        3: '3px',					
      },							
    }
  }
}

有关自定义默认主题的更多信息,请参阅主题自定义文档。

任意值

如果您需要使用一个与主题无关的 text-underline-offset 值,可以使用方括号来根据任意值动态生成属性。

html
<p class="underline-offset-[3px]">
  <!-- ... -->
</p>

有关任意值支持的更多信息,请参阅任意值文档。

Released under the MIT License.