我有一个表格,在表格的顶部是带有一些文本的表格标题。我想只在表体上放一个边框,表头不动,但我不知道怎么做。
我只尝试给表体的默认类应用边框。
<table class="float-left">
<thead>
<tr class="text-center">
<th>
This is some text I want outside of the border
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
This is some cell data I want inside the border
</td>
</tr>
</tbody>
</table>
我所需要的就是tbody是表中唯一有边框的东西,当我试图给它一个边框时,什么也没有发生。
发布于 2019-05-30 23:26:09
有几种方法可以做到这一点!
第一个也是最直接的:将border-collapse
添加到表中
table { border-collapse: collapse }
tbody { border: dashed }
2)使用outline
而不是边框
tbody { outline: dashed }
(可使用正或负outline-offset:
进行调整)
3)使用box-shadow
而不是边框
tbody { box-shadow: 0 0 0 1px }
发布于 2019-05-30 18:32:37
tbody, tbody th, tbody td, tbody tr {
border: 1px solid black;
}
<table class="float-left">
<thead>
<tr class="text-center">
<th>header</th>
<th>header</th>
</tr>
</thead>
<tbody>
<tr>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
</tr>
</tbody>
</table>
这将为tbody
以及tbody中的所有th
、tr
和td
元素创建一个边框。
https://stackoverflow.com/questions/56383730
复制