Outline Style 轮廓样式
控制元素轮廓样式的实用工具。
| Class | Properties |
|---|
基本用法
设置轮廓样式
使用 outline-{style} 实用程序来更改元素轮廓的样式。
outline
outline-dashed
outline-dotted
outline-double
html
<button class="outline outline-2 outline-offset-2 ...">Button A</button>
<button class="outline-dashed outline-2 outline-offset-2 ...">Button B</button>
<button class="outline-dotted outline-2 outline-offset-2 ...">Button C</button>
<button class="outline-double outline-3 outline-offset-2 ...">Button D</button>去除轮廓
使用 outline-none 来隐藏焦点元素上的默认浏览器轮廓。
强烈建议在使用此实用程序时,为可访问性应用自己的焦点样式。
👆 将输入焦点放在预期行为上
html
<input type="text"
placeholder="Default focus style"
class="..." />
<input type="text"
placeholder="Custom focus style"
class="focus:outline-none focus:ring focus:border-blue-500 ..." />outline-none 实用程序是使用透明轮廓在后台实现的,以确保元素仍然对 Windows 高对比度模式用户可见焦点。
有条件地应用
悬停、焦点和其他状态
Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 hover:outline-dashed 只在悬停时应用 outline-dashed 实用程序。
html
<div class="outline hover:outline-dashed">
<!-- ... -->
</div>有关所有可用状态修饰符的完整列表,请查看悬停、焦点和其他状态文档。
断点和媒体查询
您还可以使用变体修饰符来针对响应式断点、深色模式、prefers-reduced-motion 等媒体查询进行定位。例如,使用 md:outline-dashed 仅在中等屏幕尺寸及以上应用 outline-dashed 实用程序。
html
<div class="outline md:outline-dashed">
<!-- ... -->
</div>