Utilities for controlling the width of an element's borders.
Use the border
, .border-0
, .border-2
, .border-4
, or .border-8
utilities to set the border width for all sides of an element.
<div class="border-0 border-indigo-600 ..."></div>
<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>
Use the border-{side}
, .border-{side}-0
, .border-{side}-2
, .border-{side}-4
, or .border-{side}-8
utilities to set the border width for one side of an element.
<div class="border-t-2 border-fuchsia-600 ..."></div>
<div class="border-r-2 border-fuchsia-600 ..."></div>
<div class="border-b-2 border-fuchsia-600 ..."></div>
<div class="border-l-2 border-fuchsia-600 ..."></div>
You can also add borders between child elements using the divide-{x/y}-{width}
and divide-{color}
utilities.
Learn more in the Divide Width and Divide Color documentation.
<div class="divide-y divide-light-blue-400 ...">
<div>1</div>
<div>2</div>
<div>3</div>
<div></div>
</div>
To control the border width of an element at a specific breakpoint, add a {screen}:
prefix to any existing border width utility. For example, use md:border-t-4
to apply the border-t-4
utility at only medium screen sizes and above.
<div class="border-2 md:border-t-4 ..."></div>
For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.
By default, Tailwind provides five border-width
utilities, and the same number of utilities per side (top, right, bottom, and left). You change, add, or remove these by editing the theme.borderWidth
section of your Tailwind config. The values in this section will also control which utilities will be generated side.
// tailwind.config.js
module.exports = {
theme: {
borderWidth: {
DEFAULT: '1px',
'0': '0',
'2': '2px',
+ '3': '3px',
'4': '4px',
+ '6': '6px',
- '8': '8px',
}
}
}
默認情況下, 只有 響應式 的 border width 變化模式 (variants) 會產生。
在 tailwind.config.js
的 variants
區塊中變更 borderWidth
屬性來決定有哪些變化模式會生成。
舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。
// tailwind.config.js
module.exports = {
variants: {
extend: {
// ...
+ borderWidth: ['responsive', 'hover'],
}
}
}
如果你不打算在專案中使用 border width 功能,可以在你的設定檔裡的 corePlugins
屬性中將 borderWidth
設定為 false
來停用功能:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ borderWidth: false,
}
}