1. Borders
  2. border-width

Borders

边框宽度

用于控制元素边框宽度的功能类。

ClassStyles
border
border-width: 1px;
border-<number>
border-width: <number>px;
border-(length:<custom-property>)
border-width: var(<custom-property>);
border-[<value>]
border-width: <value>;
border-x
border-inline-width: 1px;
border-x-<number>
border-inline-width: <number>px;
border-x-(length:<custom-property>)
border-inline-width: var(<custom-property>);
border-x-[<value>]
border-inline-width: <value>;
border-y
border-block-width: 1px;
border-y-<number>
border-block-width: <number>px;

示例

设置边框宽度

使用 border-{width} 功能类来设置元素所有边的边框宽度:

border

border-2

border-4

border-8

<div class="border border-indigo-600 ..."></div><div class="border-2 border-indigo-600 ..."></div><div class="border-4 border-indigo-600 ..."></div><div class="border-8 border-indigo-600 ..."></div>

设置单边边框

使用 border-{t|r|b|l}-{width} 功能类来设置元素某一边的边框宽度:

border-t-4

border-r-4

border-b-4

border-l-4

<div class="border-t-4 border-indigo-500 ..."></div><div class="border-r-4 border-indigo-500 ..."></div><div class="border-b-4 border-indigo-500 ..."></div><div class="border-l-4 border-indigo-500 ..."></div>

使用水平和垂直边框

使用 border-{x|y}-{width} 功能类来同时设置元素水平或垂直方向边的边框宽度:

border-x-4

border-y-4

<div class="border-x-4 border-indigo-500 ..."></div><div class="border-y-4 border-indigo-500 ..."></div>

使用逻辑属性

使用 border-{s|e}-{width} 功能类来根据当前书写方向设置元素边框的宽度:

Left-to-right

Right-to-left

<div dir="ltr">  <div class="border-s-4 ..."></div></div><div dir="rtl">  <div class="border-s-4 ..."></div></div>

边框分隔线

使用 divide-{x/y}-{width} 功能类来在一组元素之间添加分隔线:

01
02
03
<div class="grid grid-cols-3 divide-x-4">  <div>01</div>  <div>02</div>  <div>03</div></div>

反转子元素顺序

如果你的元素是反向排序的(例如使用 flex-row-reverseflex-col-reverse),请使用 divide-x-reversedivide-y-reverse 功能类来确保边框添加到每个元素的正确侧:

01
02
03
<div class="flex flex-col-reverse divide-y-4 divide-y-reverse divide-gray-200">  <div>01</div>  <div>02</div>  <div>03</div></div>

使用自定义值

Use the border-[<value>] syntax to set the border width based on a completely custom value:

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

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

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

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

响应式设计

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

<div class="border-2 md:border-t-4 ...">  <!-- ... --></div>

Learn more about using variants in the variants documentation.

版权所有 © 2025 Tailwind Labs Inc.·商标政策