admin管理员组文章数量:1399912
When I try to combine border-separate
(I need it for border-spacing-y-2
) with divide-y
, then divide-y
is ignored until I remove border-separate
. Why is that and what is the best practice to get vertical spacing between table rows and horizontal dividers?
Playground:
Once I remove border-separate
it looks like this:
The horizontal divider is now visible, but the vertical spacing is gone. How to get both?
When I try to combine border-separate
(I need it for border-spacing-y-2
) with divide-y
, then divide-y
is ignored until I remove border-separate
. Why is that and what is the best practice to get vertical spacing between table rows and horizontal dividers?
Playground: https://play.tailwindcss/ZwI9Szxm23
Once I remove border-separate
it looks like this:
The horizontal divider is now visible, but the vertical spacing is gone. How to get both?
2 Answers
Reset to default 2I would say that border-spacing
is not the ideal property to use to space out table rows vertically. Instead, you could consider applying vertical padding to the table cells and adding borders to the table rows:
<script src="https://unpkg/@tailwindcss/[email protected]"></script>
<table class="w-full text-left">
<thead>
<tr>
<th class="py-2">Name</th>
<th class="py-2">Age</th>
<th class="py-2">City</th>
</tr>
</thead>
<tbody>
<tr class="border-t">
<td class="py-2">John Doe</td>
<td class="py-2">28</td>
<td class="py-2">New York</td>
</tr>
<tr class="border-t">
<td class="py-2">Jane Smith</td>
<td class="py-2">34</td>
<td class="py-2">Los Angeles</td>
</tr>
<tr class="border-t">
<td class="py-2">Sam Wilson</td>
<td class="py-2">22</td>
<td class="py-2">Chicago</td>
</tr>
</tbody>
</table>
The reason the borders don't show because in the separated borders model, all borders on row groups and rows are ignored. So to get the effect you want with separated borders, the border settings must be inherited by the table cells. This can be done with a little arbitrary variants magic.
<script src="https://unpkg/@tailwindcss/[email protected]"></script>
<table class="w-full border-separate border-spacing-y-2
divide-y-2 [&_thead_tr,&_th]:[border:inherit] text-left">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody class="divide-y [&_td]:[border:inherit]">
<tr>
<td>John Doe</td>
<td>28</td>
<td>New York</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>34</td>
<td>Los Angeles</td>
</tr>
<tr>
<td>Sam Wilson</td>
<td>22</td>
<td>Chicago</td>
</tr>
</tbody>
</table>
https://play.tailwindcss/JPqtsvnl7J
本文标签: cssHow to combine borderseparate with divideyStack Overflow
版权声明:本文标题:css - How to combine border-separate with divide-y? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744228475a2596208.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论