排版
用于控制元素文本颜色的工具。
¥Basic usage
¥Setting the text color
使用 text-*
工具来控制元素的文本颜色。
¥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>
<p class="text-sky-400">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>
<p class="text-sky-400/100">The quick brown fox...</p> <p class="text-sky-400/75">The quick brown fox...</p> <p class="text-sky-400/50">The quick brown fox...</p> <p class="text-sky-400/25">The quick brown fox...</p> <p class="text-sky-400/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>
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.
尝试将鼠标悬停在文本上以查看预期的行为
The quick brown fox jumps over the lazy dog.
<p class="text-slate-500 hover:text-blue-600">The quick brown fox...</p>
<p class="text-slate-400 hover:text-sky-400">The quick brown fox...</p>
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
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.
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.