Skip to content

Text Decoration Color 文本装饰颜色

控制文本装饰颜色的实用工具。

ClassProperties

基本用法

设置文本装饰颜色

使用 decoration-{color} 实用工具来改变元素的文本装饰颜色。

I’m Derek, an astro-engineer based in Tattooine. I like to build X-Wings at My Company, Inc. Outside of work, I like to watch pod-racing and have light-saber fights.

html
<div>
  <p>
    I’m Derek, an astro-engineer based in Tattooine. I like to build X-Wings at
    <a class="underline decoration-sky-500">My Company, Inc</a>.
    Outside of work, I like to <a class="underline decoration-pink-500">watch
    pod-racing</a> and have <a class="underline decoration-indigo-500">light-saber</a> fights.
  </p>
</div>

更改不透明度

使用颜色不透明度修饰符来控制元素文本装饰颜色的不透明度。

I’m Derek, an astro-engineer based in Tattooine. I like to build X-Wings at My Company, Inc. Outside of work, I like to watch pod-racing and have light-saber fights.

html
<div>
  <p>
    I’m Derek, an astro-engineer based in Tattooine. I like to build X-Wings at
    <a class="underline decoration-sky-500/30">My Company, Inc</a>.
    Outside of work, I like to <a class="underline decoration-pink-500/30">watch
    pod-racing</a> and have <a class="underline decoration-indigo-500/30">light-saber</a> fights.
  </p>
</div>

您可以使用您的不透明度比例尺中定义的任何值,或者如果需要偏离设计令牌,也可以使用任意值。

html
<strong class="underline decoration-sky-500/[.33]"></strong>

有条件地应用

悬停、焦点和其他状态

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

html
<p class="underline decoration-sky-600 hover:decoration-blue-400">
  <!-- ... -->
</p>

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

断点和媒体查询

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

html
<p class="underline decoration-sky-600 md:decoration-blue-400">
  <!-- ... -->
</p>

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

使用自定义值

定制您的主题

默认情况下,Tailwind 将整个默认颜色调色板作为文本装饰颜色可用。您可以通过编辑您的 tailwind.config.js 文件中的 theme.colorstheme.extend.colors 来自定义您的颜色调色板。

js
module.exports = {
  theme: {
    extend: {
      colors: {						
        'regal-blue': '#243c5a',	
      },							
    }
  }
}

或者,您可以通过编辑 tailwind.config.js 文件中的 theme.textDecorationColortheme.extend.textDecorationColor 来自定义文本颜色。

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

任意值

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

html
<p class="decoration-[#50d71e]">
  <!-- ... -->
</p>

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

Released under the MIT License.