- 入门
- 核心概念
- 定制
- Base Styles
- 布局
- Flexbox & Grid
- Flex Basis
- Flex Direction
- Flex Wrap
- Flex
- Flex Grow
- Flex Shrink
- Order
- Grid Template Columns
- Grid Column Start / End
- Grid Template Rows
- Grid Row Start / End
- Grid Auto Flow
- Grid Auto Columns
- Grid Auto Rows
- Gap
- Justify Content
- Justify Items
- Justify Self
- Align Content
- Align Items
- Align Self
- Place Content
- Place Items
- Place Self
- 间隔
- 尺寸
- 排版
- Font Family
- Font Size
- Font Smoothing
- Font Style
- Font Weight
- Font Variant Numeric
- Letter Spacing
- Line Clamp
- Line Height
- List Style Image
- List Style Position
- List Style Type
- Text Align
- Text Color
- Text Decoration
- Text Decoration Color
- Text Decoration Style
- Text Decoration Thickness
- Text Underline Offset
- Text Transform
- Text Overflow
- Text Wrap
- Text Indent
- Vertical Align
- Whitespace
- Word Break
- Hyphens
- Content
- 背景
- 边框
- Effects
- Filters
- 表格 Tables
- Transitions & Animation
- Transforms
- Interactivity
- SVG
- Accessibility
- 其他
- Install Tailwind CSS using PostCSS
- Framework Guides
- Try Tailwind CSS using the Play CDN
- Install Tailwind CSS with Next.js
- Install Tailwind CSS with Laravel
- Install Tailwind CSS with Vite
- Install Tailwind CSS with Nuxt
- Install Tailwind CSS with Gatsby
- Install Tailwind CSS with SolidJS
- Install Tailwind CSS with SvelteKit
- Install Tailwind CSS with Angular
- Install Tailwind CSS with Ruby on Rails
- Install Tailwind CSS with Remix
- Install Tailwind CSS with Phoenix
- Install Tailwind CSS with Parcel
- Install Tailwind CSS with Symfony
- Install Tailwind CSS with Meteor
- Install Tailwind CSS with Create React App
- Install Tailwind CSS with Adonis
- Install Tailwind CSS With Ember.js
- Install Tailwind CSS with Astro
- Install Tailwind CSS with Qwik
- Install Tailwind CSS with Rspack
Border Width
Utilities for controlling the width of an element's borders.
Quick reference
Class | Properties |
---|---|
border-0 | border-width: 0px; |
border-2 | border-width: 2px; |
border-4 | border-width: 4px; |
border-8 | border-width: 8px; |
border | border-width: 1px; |
border-x-0 | border-left-width: 0px; border-right-width: 0px; |
border-x-2 | border-left-width: 2px; border-right-width: 2px; |
border-x-4 | border-left-width: 4px; border-right-width: 4px; |
border-x-8 | border-left-width: 8px; border-right-width: 8px; |
border-x | border-left-width: 1px; border-right-width: 1px; |
border-y-0 | border-top-width: 0px; border-bottom-width: 0px; |
border-y-2 | border-top-width: 2px; border-bottom-width: 2px; |
border-y-4 | border-top-width: 4px; border-bottom-width: 4px; |
border-y-8 | border-top-width: 8px; border-bottom-width: 8px; |
border-y | border-top-width: 1px; border-bottom-width: 1px; |
border-s-0 | border-inline-start-width: 0px; |
border-s-2 | border-inline-start-width: 2px; |
border-s-4 | border-inline-start-width: 4px; |
border-s-8 | border-inline-start-width: 8px; |
border-s | border-inline-start-width: 1px; |
border-e-0 | border-inline-end-width: 0px; |
border-e-2 | border-inline-end-width: 2px; |
border-e-4 | border-inline-end-width: 4px; |
border-e-8 | border-inline-end-width: 8px; |
border-e | border-inline-end-width: 1px; |
border-t-0 | border-top-width: 0px; |
border-t-2 | border-top-width: 2px; |
border-t-4 | border-top-width: 4px; |
border-t-8 | border-top-width: 8px; |
border-t | border-top-width: 1px; |
border-r-0 | border-right-width: 0px; |
border-r-2 | border-right-width: 2px; |
border-r-4 | border-right-width: 4px; |
border-r-8 | border-right-width: 8px; |
border-r | border-right-width: 1px; |
border-b-0 | border-bottom-width: 0px; |
border-b-2 | border-bottom-width: 2px; |
border-b-4 | border-bottom-width: 4px; |
border-b-8 | border-bottom-width: 8px; |
border-b | border-bottom-width: 1px; |
border-l-0 | border-left-width: 0px; |
border-l-2 | border-left-width: 2px; |
border-l-4 | border-left-width: 4px; |
border-l-8 | border-left-width: 8px; |
border-l | border-left-width: 1px; |
Basic usage
All sides
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>
Individual sides
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>
Horizontal and vertical sides
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>
Between elements
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>
Learn more in the Divide Width and Divide Color documentation.
Using logical properties
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>
For more control, you can also use the LTR and RTL modifiers to conditionally apply specific styles depending on the current text direction.
Using without Preflight
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>
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 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.
Applying conditionally
Hover, focus, and other states
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:border-t-4
to only apply the border-t-4
utility on hover.
<div class="border-2 hover:border-t-4">
<!-- ... -->
</div>
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
Breakpoints and media queries
You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. 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>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
Using custom values
Customizing your theme
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.
Arbitrary values
If you need to use a one-off border-width
value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.
<div class="border-t-[3px]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论