返回介绍

Text Color

发布于 2024-07-30 22:16:06 字数 153938 浏览 0 评论 0 收藏 0

Utilities for controlling the text color of an element.

Quick reference

ClassPreview 
text-inheritAa
text-currentAa
text-transparentAa
text-blackAa
text-whiteAa
text-slate-50Aa
text-slate-100Aa
text-slate-200Aa
text-slate-300Aa
text-slate-400Aa
text-slate-500Aa
text-slate-600Aa
text-slate-700Aa
text-slate-800Aa
text-slate-900Aa
text-slate-950Aa
text-gray-50Aa
text-gray-100Aa
text-gray-200Aa
text-gray-300Aa
text-gray-400Aa
text-gray-500Aa
text-gray-600Aa
text-gray-700Aa
text-gray-800Aa
text-gray-900Aa
text-gray-950Aa
text-zinc-50Aa
text-zinc-100Aa
text-zinc-200Aa
text-zinc-300Aa
text-zinc-400Aa
text-zinc-500Aa
text-zinc-600Aa
text-zinc-700Aa
text-zinc-800Aa
text-zinc-900Aa
text-zinc-950Aa
text-neutral-50Aa
text-neutral-100Aa
text-neutral-200Aa
text-neutral-300Aa
text-neutral-400Aa
text-neutral-500Aa
text-neutral-600Aa
text-neutral-700Aa
text-neutral-800Aa
text-neutral-900Aa
text-neutral-950Aa
text-stone-50Aa
text-stone-100Aa
text-stone-200Aa
text-stone-300Aa
text-stone-400Aa
text-stone-500Aa
text-stone-600Aa
text-stone-700Aa
text-stone-800Aa
text-stone-900Aa
text-stone-950Aa
text-red-50Aa
text-red-100Aa
text-red-200Aa
text-red-300Aa
text-red-400Aa
text-red-500Aa
text-red-600Aa
text-red-700Aa
text-red-800Aa
text-red-900Aa
text-red-950Aa
text-orange-50Aa
text-orange-100Aa
text-orange-200Aa
text-orange-300Aa
text-orange-400Aa
text-orange-500Aa
text-orange-600Aa
text-orange-700Aa
text-orange-800Aa
text-orange-900Aa
text-orange-950Aa
text-amber-50Aa
text-amber-100Aa
text-amber-200Aa
text-amber-300Aa
text-amber-400Aa
text-amber-500Aa
text-amber-600Aa
text-amber-700Aa
text-amber-800Aa
text-amber-900Aa
text-amber-950Aa
text-yellow-50Aa
text-yellow-100Aa
text-yellow-200Aa
text-yellow-300Aa
text-yellow-400Aa
text-yellow-500Aa
text-yellow-600Aa
text-yellow-700Aa
text-yellow-800Aa
text-yellow-900Aa
text-yellow-950Aa
text-lime-50Aa
text-lime-100Aa
text-lime-200Aa
text-lime-300Aa
text-lime-400Aa
text-lime-500Aa
text-lime-600Aa
text-lime-700Aa
text-lime-800Aa
text-lime-900Aa
text-lime-950Aa
text-green-50Aa
text-green-100Aa
text-green-200Aa
text-green-300Aa
text-green-400Aa
text-green-500Aa
text-green-600Aa
text-green-700Aa
text-green-800Aa
text-green-900Aa
text-green-950Aa
text-emerald-50Aa
text-emerald-100Aa
text-emerald-200Aa
text-emerald-300Aa
text-emerald-400Aa
text-emerald-500Aa
text-emerald-600Aa
text-emerald-700Aa
text-emerald-800Aa
text-emerald-900Aa
text-emerald-950Aa
text-teal-50Aa
text-teal-100Aa
text-teal-200Aa
text-teal-300Aa
text-teal-400Aa
text-teal-500Aa
text-teal-600Aa
text-teal-700Aa
text-teal-800Aa
text-teal-900Aa
text-teal-950Aa
text-cyan-50Aa
text-cyan-100Aa
text-cyan-200Aa
text-cyan-300Aa
text-cyan-400Aa
text-cyan-500Aa
text-cyan-600Aa
text-cyan-700Aa
text-cyan-800Aa
text-cyan-900Aa
text-cyan-950Aa
text-sky-50Aa
text-sky-100Aa
text-sky-200Aa
text-sky-300Aa
text-sky-400Aa
text-sky-500Aa
text-sky-600Aa
text-sky-700Aa
text-sky-800Aa
text-sky-900Aa
text-sky-950Aa
text-blue-50Aa
text-blue-100Aa
text-blue-200Aa
text-blue-300Aa
text-blue-400Aa
text-blue-500Aa
text-blue-600Aa
text-blue-700Aa
text-blue-800Aa
text-blue-900Aa
text-blue-950Aa
text-indigo-50Aa
text-indigo-100Aa
text-indigo-200Aa
text-indigo-300Aa
text-indigo-400Aa
text-indigo-500Aa
text-indigo-600Aa
text-indigo-700Aa
text-indigo-800Aa
text-indigo-900Aa
text-indigo-950Aa
text-violet-50Aa
text-violet-100Aa
text-violet-200Aa
text-violet-300Aa
text-violet-400Aa
text-violet-500Aa
text-violet-600Aa
text-violet-700Aa
text-violet-800Aa
text-violet-900Aa
text-violet-950Aa
text-purple-50Aa
text-purple-100Aa
text-purple-200Aa
text-purple-300Aa
text-purple-400Aa
text-purple-500Aa
text-purple-600Aa
text-purple-700Aa
text-purple-800Aa
text-purple-900Aa
text-purple-950Aa
text-fuchsia-50Aa
text-fuchsia-100Aa
text-fuchsia-200Aa
text-fuchsia-300Aa
text-fuchsia-400Aa
text-fuchsia-500Aa
text-fuchsia-600Aa
text-fuchsia-700Aa
text-fuchsia-800Aa
text-fuchsia-900Aa
text-fuchsia-950Aa
text-pink-50Aa
text-pink-100Aa
text-pink-200Aa
text-pink-300Aa
text-pink-400Aa
text-pink-500Aa
text-pink-600Aa
text-pink-700Aa
text-pink-800Aa
text-pink-900Aa
text-pink-950Aa
text-rose-50Aa
text-rose-100Aa
text-rose-200Aa
text-rose-300Aa
text-rose-400Aa
text-rose-500Aa
text-rose-600Aa
text-rose-700Aa
text-rose-800Aa
text-rose-900Aa
text-rose-950Aa

Basic usage

Setting the text color

Use the text-* utilities to control the text color of an element.

The quick brown fox jumps over the lazy dog.

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

Changing the opacity

Use the color opacity modifier to control the opacity of an element’s text color.

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>

You can use any value defined in your opacity scale, or use arbitrary values if you need to deviate from your design tokens.

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

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:text-blue-600 to only apply the text-blue-600 utility on hover.

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>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:text-green-600 to apply the text-green-600 utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

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.

Arbitrary values

If you need to use a one-off color value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

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

Learn more about arbitrary value support in the arbitrary values documentation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文