1. 边框
  2. 分割宽度

Quick reference

Class
Properties
divide-x-0 > * + *border-right-width: 0px; border-left-width: 0px;
divide-x-2 > * + *border-right-width: 0px; border-left-width: 2px;
divide-x-4 > * + *border-right-width: 0px; border-left-width: 4px;
divide-x-8 > * + *border-right-width: 0px; border-left-width: 8px;
divide-x > * + *border-right-width: 0px; border-left-width: 1px;
divide-y-0 > * + *border-top-width: 0px; border-bottom-width: 0px;
divide-y-2 > * + *border-top-width: 2px; border-bottom-width: 0px;
divide-y-4 > * + *border-top-width: 4px; border-bottom-width: 0px;
divide-y-8 > * + *border-top-width: 8px; border-bottom-width: 0px;
divide-y > * + *border-top-width: 1px; border-bottom-width: 0px;
divide-y-reverse > * + *--tw-divide-y-reverse: 1;
divide-x-reverse > * + *--tw-divide-x-reverse: 1;

基本用法

¥Basic usage

在水平子项之间添加边框

¥Add borders between horizontal children

使用 divide-x-* 工具在水平元素之间添加边框。

¥Use the divide-x-* utilities to add borders between horizontal elements.

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

在堆叠的子级之间添加边框

¥Add borders between stacked children

使用 divide-y-* 工具在堆叠元素之间添加边框。

¥Use the divide-y-* utilities to add borders between stacked elements.

01
02
03
<div class="grid grid-cols-1 divide-y">
  <div>01</div>
  <div>02</div>
  <div>03</div>
</div>

反转子顺序

¥Reversing children order

如果你的元素顺序相反(例如使用 flex-row-reverseflex-col-reverse),请使用 divide-x-reversedivide-y-reverse 工具确保将边框添加到每个元素的正确一侧。

¥If your elements are in reverse order (using say flex-row-reverse or flex-col-reverse), use the divide-x-reverse or divide-y-reverse utilities to ensure the border is added to the correct side of each element.

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

有条件地应用

悬停、聚焦和其他状态

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:divide-y-8 to only apply the divide-y-8 utility on hover.

<div class="divide-y divide-gray-400 hover:divide-y-8">
  <!-- ... -->
</div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

断点和媒体查询

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:divide-y-8 to apply the divide-y-8 utility at only medium screen sizes and above.

<div class="divide-y divide-gray-400 md:divide-y-8">
  <!-- ... -->
</div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


使用自定义值

¥Using custom values

自定义主题

¥Customizing your theme

默认情况下,分界宽度比例从 borderWidth 比例继承其值,因此如果你想同时自定义边框宽度和分界宽度的值,请使用 tailwind.config.js 文件的 theme.borderWidth 部分。

¥The divide width scale inherits its values from the borderWidth scale by default, so if you’d like to customize your values for both border width and divide width together, use the theme.borderWidth section of your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    borderWidth: {
      DEFAULT: '1px',
      '0': '0',
      '2': '2px',
      '3': '3px',
      '4': '4px',
      '6': '6px',
      '8': '8px',
    }
  }
}

要仅自定义分割宽度值,请使用 tailwind.config.js 文件的 theme.divideWidth 部分。

¥To customize only the divide width values, use the theme.divideWidth section of your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    divideWidth: {
      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 divide 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="divide-x-[3px]">
  <!-- ... -->
</div>

Learn more about arbitrary value support in the arbitrary values documentation.