交互
用于控制表单控件强调色的工具。
¥Basic usage
¥Setting the accent color
使用 accent-*
工具更改元素的强调色。这有助于通过覆盖浏览器的默认颜色来设置复选框和单选组等元素的样式。
¥Use the accent-*
utilities to change the accent color of an element. This is helpful for styling elements like checkboxes and radio groups by overriding the browser’s default color.
<label>
<input type="checkbox" checked> Browser default
</label>
<label>
<input type="checkbox" class="accent-pink-500" checked> Customized
</label>
¥Changing the opacity
虽然可以使用颜色透明度修饰符来控制强调色的透明度,但目前仅 Firefox 支持 rgba()
alpha 值(上次测试时间为 2021 年 11 月)。
¥While it’s possible to control the opacity of the accent color using the color opacity modifier, the rgba()
alpha value is only supported in Firefox at this time (last tested November 2021).
<input type="checkbox" class="accent-emerald-500/25" checked> Emerald
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:accent-pink-500
to only apply the accent-pink-500
utility on hover.
<input type="checkbox" class="accent-pink-300 focus:accent-pink-500" checked>
请注意,虽然可以使用 hover
和 active
修饰符设置强调色,但生成的颜色将与你设置的略有不同,因为浏览器会自动调整这两种状态的强调色的亮度。
¥Note, while it’s possible to set an accent color using the hover
and active
modifiers, the resulting color will be slightly different than what you set, as browsers automatically adjust the brightness of the accent color for these two states.
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:accent-pink-500
to apply the accent-pink-500
utility at only medium screen sizes and above.
<input type="checkbox" class="accent-pink-300 md:accent-pink-500" checked>
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 accent 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 accent colors by editing theme.accentColor
or theme.extend.accentColor
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 accent-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.
<input type="checkbox" class="accent-[#50d71e]" checked>
Learn more about arbitrary value support in the arbitrary values documentation.