边框
添加轮廓环时模拟偏移的工具。
¥Basic usage
¥Setting the ring offset width
使用 ring-offset-2
和 ring-offset-4
等工具通过添加纯白框阴影并增加随附轮廓环的厚度以适应偏移来模拟偏移。
¥Use utilities like ring-offset-2
and ring-offset-4
to simulate an offset by adding solid white box-shadow and increasing the thickness of the accompanying outline ring to accommodate the offset.
ring-offset-0
ring-offset-2
ring-offset-4
<button class="... ring ring-pink-500 ring-offset-0">Button A</button>
<button class="... ring ring-pink-500 ring-offset-2">Button B</button>
<button class="... ring ring-pink-500 ring-offset-4">Button C</button>
¥Changing the offset color
你实际上无法在 CSS 中偏移框阴影,因此我们必须使用与父背景颜色匹配的纯色阴影来伪造它。我们默认使用白色,但如果你要在不同的背景颜色上添加环偏移,请使用环偏移颜色工具(如 ring-offset-slate-50
)来匹配父背景颜色:
¥You can’t actually offset a box-shadow in CSS, so we have to fake it using a solid color shadow that matches the parent background color. We use white by default, but if you are adding a ring offset over a different background color, use the ring offset color utilities, like ring-offset-slate-50
, to match the parent background color:
ring-offset-slate-50 dark:ring-offset-slate-900
<button class="ring ring-pink-500 ring-offset-2 ring-offset-slate-50 dark:ring-offset-slate-900 ...">
Save Changes
</button>
有关详细信息,请参阅 环偏移颜色 文档。
¥For more information, see the ring offset color documentation.
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:ring-offset-4
to only apply the ring-offset-4
utility on hover.
<button class="ring-2 ring-offset-2 hover:ring-offset-4">
<!-- ... -->
</button>
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:ring-offset-4
to apply the ring-offset-4
utility at only medium screen sizes and above.
<button class="ring-2 ring-offset-2 md:ring-offset-4">
<!-- ... -->
</button>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
¥Using custom values
¥Customizing your theme
要自定义生成哪些环偏移宽度工具,请在 tailwind.config.js
文件的 theme
部分的 ringOffsetWidth
键下添加自定义值。
¥To customize which ring offset width utilities are generated, add your custom values under ringOffsetWidth
key in the theme
section of your tailwind.config.js
file.
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
ringOffsetWidth: {
'3': '3px',
'6': '6px',
'10': '10px',
}
}
}
}
在 主题定制 文档中了解有关自定义默认主题的更多信息。
¥Learn more about customizing the default theme in the theme customization documentation.
¥Arbitrary values
If you need to use a one-off ring-offset
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.
<div class="ring-offset-[3px]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.