Utilities for simulating an offset when adding outline rings.
Use the ring-offset-{width}
utilities to simulate an offset by adding solid white box-shadow and increasing the thickness of the accompanying outline ring to accommodate the offset.
<button class="... ring ring-pink-600 ring-offset-0">ring-0</button>
<button class="... ring ring-pink-600 ring-offset-2">ring-2</button>
<button class="... ring ring-pink-600 ring-offset-4">ring-4</button>
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, you should use the ring-offset-{color}
utilities to match the parent background color:
bg-green-100
<div class="... bg-green-100">
<button class="... ring ring-green-600 ring-offset-4 ring-offset-green-100">
ring-offset-green-100
</button>
</div>
For more information, see the ringOffsetColor documentation.
To control the ring offset width at a specific breakpoint, add a {screen}:
prefix to any existing ring offset width utility. 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>
For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.
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.
// tailwind.config.js
module.exports = {
theme: {
extend: {
ringOffsetWidth: {
'3': '3px',
'6': '6px',
'10': '10px',
}
}
}
}
Learn more about customizing the default theme in the theme customization documentation.
默認情況下, 只有 響應式、focus-within 和 focus 的 ring offset width 變化模式 (variants) 會產生。
在 tailwind.config.js
的 variants
區塊中變更 ringOffsetWidth
屬性來決定有哪些變化模式會生成。
舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。
// tailwind.config.js
module.exports = {
variants: {
extend: {
// ...
+ ringOffsetWidth: ['responsive', 'hover'],
}
}
}
如果你不打算在專案中使用 ring offset width 功能,可以在你的設定檔裡的 corePlugins
屬性中將 ringOffsetWidth
設定為 false
來停用功能:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ ringOffsetWidth: false,
}
}