1. 边框
  2. 轮廓宽度

边框

轮廓宽度

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

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

示例

基本示例

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

轮廓

outline-2

outline-4

<button class="outline outline-offset-2 ...">按钮 A</button>
<button class="outline-2 outline-offset-2 ...">按钮 B</button>
<button class="outline-4 outline-offset-2 ...">按钮 C</button>

聚焦时的应用

Prefix an outline-width utility with a variant like focus:* to only apply the utility in that state:

聚焦按钮以查看添加的轮廓

<button class="outline-offset-2 outline-sky-500 focus:outline-2 ...">保存更改</button>

Learn more about using variants in the variants documentation.

使用自定义值

Use the outline-[<value>] syntax to set the 轮廓宽度 based on a completely custom value:

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

For CSS variables, you can also use the outline-(length:<custom-property>) syntax:

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

This is just a shorthand for outline-[length:var(<custom-property>)] that adds the var() function for you automatically.

响应式设计

Prefix an outline-width utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

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

Learn more about using variants in the variants documentation.