--- title: empty-cells slug: Web/CSS/empty-cells tags: - CSS - CSS属性 - CSS表格 translation_of: Web/CSS/empty-cells ---
CSS中 empty-cells 属性定义了用户端 {{glossary("user agent")}} 应该怎么来渲染表格 {{htmlelement("table")}} 中没有可见内容的单元格的边框和背景。
/* Keyword values */ empty-cells: show; empty-cells: hide; /* Global values */ empty-cells: inherit; empty-cells: initial; empty-cells: unset;
只有当 {{cssxref("border-collapse")}} 属性值是 separate 时,才会生效。
{{cssinfo}}
empty-cells 的属性值必须是以下取值中的一个。
showhide<table class="table_1">
<tr>
<td>Moe</td>
<td>Larry</td>
</tr>
<tr>
<td>Curly</td>
<td></td>
</tr>
</table>
<br>
<table class="table_2">
<tr>
<td>Moe</td>
<td>Larry</td>
</tr>
<tr>
<td>Curly</td>
<td></td>
</tr>
</table>
.table_1 {
empty-cells: show;
}
.table_2 {
empty-cells: hide;
}
td,
th {
border: 1px solid gray;
padding: 0.5rem;
}
{{ EmbedLiveSample('Examples', '100%', '200') }}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('CSS2.1', 'tables.html#empty-cells', 'empty-cells')}} | {{Spec2('CSS2.1')}} | Initial definition. |
{{Compat("css.properties.empty-cells")}}