
边框
用于控制元素边框宽度的工具。
使用 border、border-0、border-2、border-4 或 border-8 工具来设置元素所有边的边框宽度。
🌐 Use the border, border-0, border-2, border-4, or border-8 utilities to set the border width for all sides of an element.
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><div class="border border-sky-500"></div> <div class="border-2 border-sky-500"></div> <div class="border-4 border-sky-500"></div> <div class="border-8 border-sky-500"></div>
使用 border-*、border-*-0、border-*-2、border-*-4 或 border-*-8 工具来设置元素一侧的边框宽度。
🌐 Use the border-*, border-*-0, border-*-2, border-*-4, or border-*-8 utilities to set the border width for one side of an element.
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-* 和 border-y-* 工具可以同时设置元素两边的边框宽度。
🌐 Use the border-x-* and border-y-* utilities to set the border width on two sides of an element at the same time.
border-x-4
border-y-4
<div class="border-x-4 border-indigo-500 ..."></div>
<div class="border-y-4 border-indigo-500 ..."></div>
你也可以使用 divide-x-* 和 divide-y-* 宽度工具以及 divide-* 颜色工具在子元素之间添加边框。
🌐 You can also add borders between child elements using the divide-x-* and divide-y-* width utilities along with the divide-* color utilities.
<div class="divide-y divide-slate-200 ..."> <div>01</div> <div>02</div> <div>03</div> </div><div class="divide-y divide-slate-700 ..."> <div>01</div> <div>02</div> <div>03</div> </div>
在 Divide Width 和 Divide Color 文档中了解更多信息。
🌐 Learn more in the Divide Width and Divide Color documentation.
使用 border-s-* 和 border-e-* 工具来设置 border-inline-start-width 和 border-inline-end-width 逻辑属性,它们根据文本方向映射到左边或右边边框。
🌐 Use the border-s-* and border-e-* utilities to set the border-inline-start-width and border-inline-end-width logical properties, which map to either the left or right border based on the text direction.
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>
为了获得更多的控制,你还可以使用 LTR 和 RTL 修改器 根据当前的文本方向有条件地应用特定样式。
🌐 For more control, you can also use the LTR and RTL modifiers to conditionally apply specific styles depending on the current text direction.
如果你在项目中禁用预检,每次使用border-width边框实用工具时,都需要包含一个边框样式实用工具,边框才能实际生效:
🌐 If you’ve disabled Preflight in your project, you’ll need to include a border style utility any time you use one of the border-width utilities for the border to actually take effect:
<div class="border-4 border-indigo-500 ...">
<div class="border-4 border-solid border-indigo-500 ...">
<!-- ... -->
</div>
这是因为浏览器默认将大多数元素的 border-style 设置为 none,所以单独添加 border-width 并不足以渲染边框。
🌐 This is because browsers set the border-style of most elements to none by default, so adding a border-width on its own isn’t enough to render a border.
Preflight 应用一个全局的 边框重置,将 border-style 设置为 solid,并将 border-width 设置为 0,这使得在使用 Preflight 的项目中,仅使用 border-width 工具就可以为元素添加边框成为可能。
🌐 Preflight applies a global border reset that sets border-style to solid and border-width to 0, which is what makes it possible to add a border to an element using just a border-width utility in projects using Preflight.
Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:border-t-4 仅在 hover 时应用 border-t-4 工具。
<div class="border-2 hover:border-t-4">
<!-- ... -->
</div>
有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。
你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:border-t-4 仅在中等屏幕尺寸及以上时应用 border-t-4 工具。
<div class="border-2 md:border-t-4">
<!-- ... -->
</div>
要了解更多信息,请查看有关 响应式设计、暗黑模式、以及 其他媒体查询修饰符 的文档。
默认情况下,Tailwind 提供五个 border-width 工具,以及每个方向(水平、垂直、上、右、下、左)相同数量的工具。你可以通过编辑 Tailwind 配置中的 theme.borderWidth 部分来更改、添加或删除这些工具。
🌐 By default, Tailwind provides five border-width utilities, and the same number of utilities per side (horizontal, vertical, top, right, bottom, and left). You change, add, or remove these by editing the theme.borderWidth section of your Tailwind config.
module.exports = {
theme: {
borderWidth: {
DEFAULT: '1px',
'0': '0',
'2': '2px',
'3': '3px',
'4': '4px',
'6': '6px',
'8': '8px',
}
}
}
在主题自定义文档中了解有关自定义默认主题的更多信息。
🌐 Learn more about customizing the default theme in the theme customization documentation.
如果你需要使用一次性的 border-width 值,而该值没有必要包含在你的主题中,请使用方括号动态生成属性,使用任意值。
<div class="border-t-[3px]">
<!-- ... -->
</div>
在 任意值 文档中了解有关任意值支持的更多信息。