1. 排版
  2. 颜色

排版

颜色

用于控制元素文本颜色的工具类。

ClassStyles
text-inherit
color: inherit;
text-current
color: currentColor;
text-transparent
color: transparent;
text-black
color: var(--color-black); /* #000 */
text-white
color: var(--color-white); /* #fff */
text-red-50
color: var(--color-red-50); /* oklch(97.1% 0.013 17.38) */
text-red-100
color: var(--color-red-100); /* oklch(93.6% 0.032 17.717) */
text-red-200
color: var(--color-red-200); /* oklch(88.5% 0.062 18.334) */
text-red-300
color: var(--color-red-300); /* oklch(80.8% 0.114 19.571) */
text-red-400
color: var(--color-red-400); /* oklch(70.4% 0.191 22.216) */

示例

基本示例

使用类似 text-blue-600text-sky-400 的工具类来控制元素的文本颜色:

敏捷的棕色狐狸跳过懒狗。

<p class="text-blue-600 dark:text-sky-400">敏捷的棕色狐狸...</p>

更改不透明度

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

敏捷的棕色狐狸跳过懒狗。

敏捷的棕色狐狸跳过懒狗。

敏捷的棕色狐狸跳过懒狗。

敏捷的棕色狐狸跳过懒狗。

<p class="text-blue-600/100 dark:text-sky-400/100">敏捷的棕色狐狸...</p><p class="text-blue-600/75 dark:text-sky-400/75">敏捷的棕色狐狸...</p><p class="text-blue-600/50 dark:text-sky-400/50">敏捷的棕色狐狸...</p><p class="text-blue-600/25 dark:text-sky-400/25">敏捷的棕色狐狸...</p>

使用自定义值

Use the text-[<value>] syntax to set the 文本颜色 based on a completely custom value:

<p class="text-[#50d71e] ...">  Lorem ipsum dolor sit amet...</p>

For CSS variables, you can also use the text-(<custom-property>) syntax:

<p class="text-(--my-color) ...">  Lorem ipsum dolor sit amet...</p>

This is just a shorthand for text-[var(<custom-property>)] that adds the var() function for you automatically.

悬停时应用

Prefix a color utility with a variant like hover:* to only apply the utility in that state:

悬停在文本上以查看预期行为

哦,我得去上网了 互联网,我对一切都迟到了!

<p class="...">  哦,我得去上网了  <a class="underline hover:text-blue-600 dark:hover:text-blue-400" href="https://en.wikipedia.org/wiki/Internet">互联网</a>,  我对一切都迟到了!</p>

Learn more about using variants in the variants documentation.

响应式设计

Prefix a color utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<p class="text-blue-600 md:text-green-600 ...">  Lorem ipsum dolor sit amet...</p>

Learn more about using variants in the variants documentation.

自定义您的主题

Use the --color-* theme variables to customize the color utilities in your project:

@theme {  --color-regal-blue: #243c5a; }

Now the text-regal-blue utility can be used in your markup:

<p class="text-regal-blue">  Lorem ipsum dolor sit amet...</p>

Learn more about customizing your theme in the theme documentation.