【发布时间】:2015-10-17 03:06:51
【问题描述】:
当表格的 tbody 为空时,Firefox 无法正确呈现表格单元格边框。
但是如果你使用伪选择器tbody:empty {display:none;}来隐藏tbody元素,一切都会按预期呈现。
table {
border-collapse: collapse;
}
th,
td {
border: 1px solid #000;
}
.fixed tbody:empty {
display: none;
}
<table class="broken">
<thead>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</tfoot>
</table>
<hr />
<table class="fixed">
<thead>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<th>1</th>
<td>2</td>
<td>3</td>
</tr>
</tfoot>
</table>
【问题讨论】:
-
提醒像我这样的人:确保您的空
<tbody>标签在同一行打开和关闭。否则,其中的空白似乎会违反:empty选择器并阻止此技巧起作用。我使用的解决方法是在<tbody>中有一个空的<tr>标记。