gpt4 book ai didi

css - 为什么 Firefox 不渲染带有空 tbody 的表格边框?

转载 作者:技术小花猫 更新时间:2023-10-29 11:18:50 24 4
gpt4 key购买 nike

当表格的主体为空时,Firefox 无法正确呈现表格单元格边框。

但是如果你使用伪选择器 tbody:empty {display:none;} 来隐藏 tbody 元素,一切都会按预期呈现。

jsfiddle

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>

最佳答案

它很可能属于 Bug 409254Bug 217769在 Firefox 上。

旁注:虽然空 tbody 在 HTML 5 中是有效的,但每个行组中的单元格数量应该在一个中匹配(使用 colspan 除外)表。

解决方法是分别在表格和单元格元素上绘制边框。

table {
border-collapse: separate; /*changed from collapse*/
border-spacing: 0;
border: 1px solid;
border-width: 0 0 1px 1px; /*draw bottom and left borders*/
}
th,
td {
border: 1px solid;
border-width: 1px 1px 0 0; /*draw top and right borders*/
}

jsfiddle

关于css - 为什么 Firefox 不渲染带有空 tbody 的表格边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33168178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com