← 返回首页
empty-cells - CSS:层叠样式表 | MDN

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

empty-cells

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

CSS 中 empty-cells 属性定义了用户端 user agent 应该怎么来渲染表格 <table> 中没有可见内容的单元格的边框和背景。

css
/* Keyword values */ empty-cells: show; empty-cells: hide; /* Global values */ empty-cells: inherit; empty-cells: initial; empty-cells: unset;

只有当 border-collapse 属性值是 separate 时,才会生效。

初始值适用元素是否是继承属性计算值动画类型
show
表格单元格元素
as specified
离散值

本文内容

语法

empty-cells 的属性值必须是以下取值中的一个。

取值

show

边框和背景正常渲染。与普通元素一样。

hide

边框和背景被隐藏。

语法形式

empty-cells =
show |
hide
此语法反映了基于 CSS Table Module Level 3 的最新标准。并非所有浏览器都已实现全部内容。有关支持信息,请参阅浏览器兼容性

示例

HTML

html
<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>

CSS

css
.table_1 { empty-cells: show; } .table_2 { empty-cells: hide; } td, th { border: 1px solid gray; padding: 0.5rem; }

结果

规范

规范
Cascading Style Sheets Level 2
# empty-cells

浏览器兼容性

启用 JavaScript 以查看此浏览器兼容性表。