--- title: empty-cells slug: Web/CSS/empty-cells tags: - CSS - CSS属性 - CSS表格 translation_of: Web/CSS/empty-cells --- <div>{{CSSRef}}</div> <p>CSS中 <strong><code>empty-cells</code></strong> 属性定义了用户端 {{glossary("user agent")}} 应该怎么来渲染表格 {{htmlelement("table")}} 中没有可见内容的单元格的边框和背景。</p> <pre class="brush:css no-line-numbers">/* Keyword values */ empty-cells: show; empty-cells: hide; /* Global values */ empty-cells: inherit; empty-cells: initial; empty-cells: unset; </pre> <p>只有当 {{cssxref("border-collapse")}} 属性值是 <code>separate</code> 时,才会生效。</p> <p>{{cssinfo}}</p> <h2 id="Syntax" name="Syntax">语法</h2> <p><code>empty-cells</code> 的属性值必须是以下取值中的一个。</p> <h3 id="Values" name="Values">取值</h3> <dl> <dt><code>show</code></dt> <dd>边框和背景正常渲染。与普通元素一样。</dd> <dt><code>hide</code></dt> <dd>边框和背景被隐藏。</dd> </dl> <h3 id="语法形式">语法形式</h3> {{csssyntax}} <h2 id="Examples" name="Examples">示例</h2> <h3 id="HTML">HTML</h3> <pre class="brush: 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> </pre> <h3 id="Specifications" name="Specifications">CSS</h3> <pre class="brush: css">.table_1 { empty-cells: show; } .table_2 { empty-cells: hide; } td, th { border: 1px solid gray; padding: 0.5rem; }</pre> <h3 id="Result">Result</h3> <p>{{ EmbedLiveSample('Examples', '100%', '200') }}</p> <h2 id="Specifications" name="Specifications">规范</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS2.1', 'tables.html#empty-cells', 'empty-cells')}}</td> <td>{{Spec2('CSS2.1')}}</td> <td>Initial definition.</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2> <div> <p>{{Compat("css.properties.empty-cells")}}</p> </div>