Skip to content
全部文档

outline-width

用于控制元素轮廓宽度的工具类。

快速参考

属性
outlineoutline-width: 1px;
outline-<number>outline-width: <number>px;
outline-(length:<custom-property>)outline-width: var(<custom-property>);
outline-[<value>]outline-width: <value>;

示例

基础示例

使用 outlineoutline-2outline-4outline-<number> 工具类,设置元素轮廓的宽度:

outline

outline-2

outline-4

html
<!-- [!code classes:outline,outline-2,outline-4] -->
<button class="outline outline-offset-2 ...">Button A</button>
<button class="outline-2 outline-offset-2 ...">Button B</button>
<button class="outline-4 outline-offset-2 ...">Button C</button>

在焦点时应用

outline-width 工具类前加上 focus:* 等变体,即可只在该状态下应用该工具类:

html
<!-- [!code classes:focus:outline-2] -->
<button class="outline-offset-2 outline-sky-500 focus:outline-2 ...">Save Changes</button>

变体文档中了解更多关于使用变体的信息。

使用自定义值

使用 outline-[<value>] 等工具类,根据完全自定义的值设置轮廓宽度:

html
<div class="outline-[2vw] ...">
 <!-- ... -->
</div>

对于 CSS 变量,也可以使用 outline-(length:<custom-property>) 语法:

html
<div class="outline-(length:--my-outline-width) ...">
 <!-- ... -->
</div>

这只是 outline-[length:var(<custom-property>)] 的简写,会自动为你加上 var() 函数。

响应式设计

outline-width 工具类前加上 md: 等断点变体,即可只在中等屏幕尺寸及以上应用该工具类:

html
<div class="outline md:outline-2 ...">
 <!-- ... -->
</div>

变体文档中了解更多关于使用变体的信息。

文档译文以 MIT 协议授权;原文版权归 Tailwind Labs。湘ICP备2026005453号-2