1. 排版
  2. 文本颜色

Quick reference

Class
Preview 
text-inherit
Aa
text-current
Aa
text-transparent
Aa
text-black
Aa
text-white
Aa
text-slate-50
Aa
text-slate-100
Aa
text-slate-200
Aa
text-slate-300
Aa
text-slate-400
Aa
text-slate-500
Aa
text-slate-600
Aa
text-slate-700
Aa
text-slate-800
Aa
text-slate-900
Aa
text-slate-950
Aa
text-gray-50
Aa
text-gray-100
Aa
text-gray-200
Aa
text-gray-300
Aa
text-gray-400
Aa
text-gray-500
Aa
text-gray-600
Aa
text-gray-700
Aa
text-gray-800
Aa
text-gray-900
Aa
text-gray-950
Aa
text-zinc-50
Aa
text-zinc-100
Aa
text-zinc-200
Aa
text-zinc-300
Aa
text-zinc-400
Aa
text-zinc-500
Aa
text-zinc-600
Aa
text-zinc-700
Aa
text-zinc-800
Aa
text-zinc-900
Aa
text-zinc-950
Aa
text-neutral-50
Aa
text-neutral-100
Aa
text-neutral-200
Aa
text-neutral-300
Aa
text-neutral-400
Aa
text-neutral-500
Aa
text-neutral-600
Aa
text-neutral-700
Aa
text-neutral-800
Aa
text-neutral-900
Aa
text-neutral-950
Aa
text-stone-50
Aa
text-stone-100
Aa
text-stone-200
Aa
text-stone-300
Aa
text-stone-400
Aa
text-stone-500
Aa
text-stone-600
Aa
text-stone-700
Aa
text-stone-800
Aa
text-stone-900
Aa
text-stone-950
Aa
text-red-50
Aa
text-red-100
Aa
text-red-200
Aa
text-red-300
Aa
text-red-400
Aa
text-red-500
Aa
text-red-600
Aa
text-red-700
Aa
text-red-800
Aa
text-red-900
Aa
text-red-950
Aa
text-orange-50
Aa
text-orange-100
Aa
text-orange-200
Aa
text-orange-300
Aa
text-orange-400
Aa
text-orange-500
Aa
text-orange-600
Aa
text-orange-700
Aa
text-orange-800
Aa
text-orange-900
Aa
text-orange-950
Aa
text-amber-50
Aa
text-amber-100
Aa
text-amber-200
Aa
text-amber-300
Aa
text-amber-400
Aa
text-amber-500
Aa
text-amber-600
Aa
text-amber-700
Aa
text-amber-800
Aa
text-amber-900
Aa
text-amber-950
Aa
text-yellow-50
Aa
text-yellow-100
Aa
text-yellow-200
Aa
text-yellow-300
Aa
text-yellow-400
Aa
text-yellow-500
Aa
text-yellow-600
Aa
text-yellow-700
Aa
text-yellow-800
Aa
text-yellow-900
Aa
text-yellow-950
Aa
text-lime-50
Aa
text-lime-100
Aa
text-lime-200
Aa
text-lime-300
Aa
text-lime-400
Aa
text-lime-500
Aa
text-lime-600
Aa
text-lime-700
Aa
text-lime-800
Aa
text-lime-900
Aa
text-lime-950
Aa
text-green-50
Aa
text-green-100
Aa
text-green-200
Aa
text-green-300
Aa
text-green-400
Aa
text-green-500
Aa
text-green-600
Aa
text-green-700
Aa
text-green-800
Aa
text-green-900
Aa
text-green-950
Aa
text-emerald-50
Aa
text-emerald-100
Aa
text-emerald-200
Aa
text-emerald-300
Aa
text-emerald-400
Aa
text-emerald-500
Aa
text-emerald-600
Aa
text-emerald-700
Aa
text-emerald-800
Aa
text-emerald-900
Aa
text-emerald-950
Aa
text-teal-50
Aa
text-teal-100
Aa
text-teal-200
Aa
text-teal-300
Aa
text-teal-400
Aa
text-teal-500
Aa
text-teal-600
Aa
text-teal-700
Aa
text-teal-800
Aa
text-teal-900
Aa
text-teal-950
Aa
text-cyan-50
Aa
text-cyan-100
Aa
text-cyan-200
Aa
text-cyan-300
Aa
text-cyan-400
Aa
text-cyan-500
Aa
text-cyan-600
Aa
text-cyan-700
Aa
text-cyan-800
Aa
text-cyan-900
Aa
text-cyan-950
Aa
text-sky-50
Aa
text-sky-100
Aa
text-sky-200
Aa
text-sky-300
Aa
text-sky-400
Aa
text-sky-500
Aa
text-sky-600
Aa
text-sky-700
Aa
text-sky-800
Aa
text-sky-900
Aa
text-sky-950
Aa
text-blue-50
Aa
text-blue-100
Aa
text-blue-200
Aa
text-blue-300
Aa
text-blue-400
Aa
text-blue-500
Aa
text-blue-600
Aa
text-blue-700
Aa
text-blue-800
Aa
text-blue-900
Aa
text-blue-950
Aa
text-indigo-50
Aa
text-indigo-100
Aa
text-indigo-200
Aa
text-indigo-300
Aa
text-indigo-400
Aa
text-indigo-500
Aa
text-indigo-600
Aa
text-indigo-700
Aa
text-indigo-800
Aa
text-indigo-900
Aa
text-indigo-950
Aa
text-violet-50
Aa
text-violet-100
Aa
text-violet-200
Aa
text-violet-300
Aa
text-violet-400
Aa
text-violet-500
Aa
text-violet-600
Aa
text-violet-700
Aa
text-violet-800
Aa
text-violet-900
Aa
text-violet-950
Aa
text-purple-50
Aa
text-purple-100
Aa
text-purple-200
Aa
text-purple-300
Aa
text-purple-400
Aa
text-purple-500
Aa
text-purple-600
Aa
text-purple-700
Aa
text-purple-800
Aa
text-purple-900
Aa
text-purple-950
Aa
text-fuchsia-50
Aa
text-fuchsia-100
Aa
text-fuchsia-200
Aa
text-fuchsia-300
Aa
text-fuchsia-400
Aa
text-fuchsia-500
Aa
text-fuchsia-600
Aa
text-fuchsia-700
Aa
text-fuchsia-800
Aa
text-fuchsia-900
Aa
text-fuchsia-950
Aa
text-pink-50
Aa
text-pink-100
Aa
text-pink-200
Aa
text-pink-300
Aa
text-pink-400
Aa
text-pink-500
Aa
text-pink-600
Aa
text-pink-700
Aa
text-pink-800
Aa
text-pink-900
Aa
text-pink-950
Aa
text-rose-50
Aa
text-rose-100
Aa
text-rose-200
Aa
text-rose-300
Aa
text-rose-400
Aa
text-rose-500
Aa
text-rose-600
Aa
text-rose-700
Aa
text-rose-800
Aa
text-rose-900
Aa
text-rose-950
Aa

基础用法

设置文本颜色

使用 text-* 实用程序来控制元素的文本颜色。

The quick brown fox jumps over the lazy dog.

<p class="text-blue-600">The quick brown fox...</p>

更改不透明度

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

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

<p class="text-blue-600/100">The quick brown fox...</p>
<p class="text-blue-600/75">The quick brown fox...</p>
<p class="text-blue-600/50">The quick brown fox...</p>
<p class="text-blue-600/25">The quick brown fox...</p>
<p class="text-blue-600/0">The quick brown fox...</p>

您可以使用 opacity scale 中定义的任何值,或者如果您需要偏离设计令牌,则可以使用任意值。

<p class="text-blue-600/[.06]">The quick brown fox...</p>

条件应用

悬停、聚焦和其他状态

Tailwind 允许您使用变体修饰符有条件地在不同状态下应用实用程序类。例如,使用 hover:text-blue-600 来仅 在 hover应用 text-blue-600.

Try hovering over the text to see the expected behaviour

The quick brown fox jumps over the lazy dog.

<p class="text-slate-500 hover:text-blue-600">The quick brown fox...</p>

详细了解, 请参考 Hover, Focus, & Other States 文档.

断点和媒体查询

您还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗模式、首选减少运动等。例如, 使用 md:text-green-600 来应用 text-green-600 程序,适用于中等屏幕尺寸及以上。

<p class="text-blue-600 md:text-green-600">
  <!-- ... -->
</p>

进一步了解,请参考 响应式设计, 暗黑模式 媒体查询.


使用自定义值

定制你的主题

By default, Tailwind makes the entire default color palette available as text colors. You can customize your color palette by editing theme.colors or theme.extend.colors in your tailwind.config.js file.

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

Alternatively, you can customize just your text colors by editing theme.textColor or theme.extend.textColor in your tailwind.config.js file.

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

任意值

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

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

进一步了解,请参考 任意值 文档.