
表格
用于控制表格边框是合并还是分开的工具。
使用 border-collapse 将相邻单元格的边框合并为单一边框(如果可能)。请注意,这也包括折叠顶层 <table> 标签的边框。
🌐 Use border-collapse to combine adjacent cell borders into a single border when possible. Note that this includes collapsing borders on the top-level <table> tag.
| State | City |
|---|---|
| Indiana | Indianapolis |
| Ohio | Columbus |
| Michigan | Detroit |
<table class="border-collapse border border-slate-400 ..."> <thead> <tr> <th class="border border-slate-300 ...">State</th> <th class="border border-slate-300 ...">City</th> </tr> </thead> <tbody> <tr> <td class="border border-slate-300 ...">Indiana</td> <td class="border border-slate-300 ...">Indianapolis</td> </tr> <tr> <td class="border border-slate-300 ...">Ohio</td> <td class="border border-slate-300 ...">Columbus</td> </tr> <tr> <td class="border border-slate-300 ...">Michigan</td> <td class="border border-slate-300 ...">Detroit</td> </tr> </tbody> </table><table class="border-collapse border border-slate-500 ..."> <thead> <tr> <th class="border border-slate-600 ...">State</th> <th class="border border-slate-600 ...">City</th> </tr> </thead> <tbody> <tr> <td class="border border-slate-700 ...">Indiana</td> <td class="border border-slate-700 ...">Indianapolis</td> </tr> <tr> <td class="border border-slate-700 ...">Ohio</td> <td class="border border-slate-700 ...">Columbus</td> </tr> <tr> <td class="border border-slate-700 ...">Michigan</td> <td class="border border-slate-700 ...">Detroit</td> </tr> </tbody> </table>
使用 border-separate 强制每个单元格显示各自的边框。
🌐 Use border-separate to force each cell to display its own separate borders.
| State | City |
|---|---|
| Indiana | Indianapolis |
| Ohio | Columbus |
| Michigan | Detroit |
<table class="border-separate border border-slate-400 ..."> <thead> <tr> <th class="border border-slate-300 ...">State</th> <th class="border border-slate-300 ...">City</th> </tr> </thead> <tbody> <tr> <td class="border border-slate-300 ...">Indiana</td> <td class="border border-slate-300 ...">Indianapolis</td> </tr> <tr> <td class="border border-slate-300 ...">Ohio</td> <td class="border border-slate-300 ...">Columbus</td> </tr> <tr> <td class="border border-slate-300 ...">Michigan</td> <td class="border border-slate-300 ...">Detroit</td> </tr> </tbody> </table><table class="border-separate border border-slate-500 ..."> <thead> <tr> <th class="border border-slate-600 ...">State</th> <th class="border border-slate-600 ...">City</th> </tr> </thead> <tbody> <tr> <td class="border border-slate-700 ...">Indiana</td> <td class="border border-slate-700 ...">Indianapolis</td> </tr> <tr> <td class="border border-slate-700 ...">Ohio</td> <td class="border border-slate-700 ...">Columbus</td> </tr> <tr> <td class="border border-slate-700 ...">Michigan</td> <td class="border border-slate-700 ...">Detroit</td> </tr> </tbody> </table>
Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:border-collapse 仅在 hover 时应用 border-collapse 工具。
<table class="hover:border-collapse">
<!-- ... -->
</table>
有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。
你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:border-collapse 仅在中等屏幕尺寸及以上时应用 border-collapse 工具。
<table class="md:border-collapse">
<!-- ... -->
</table>