You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何我的content-visibility简易演示未达预期效果?

问题:content-visibility 在表格行元素上不生效

我尝试克隆一个基于lit和CSS contain属性的高性能HTML表格演示项目,但未能成功运行。以下是我当前的代码:

原CSS代码

.container {
  height: 100px;
  border: 1px solid #000;
  contain: strict;
  contain-intrinsic-height: 100px;
  overflow: auto;
}
tr {
  height: 21px;
  contain: strict;
  contain-intrinsic-height: auto 21px;
  content-visibility: auto;
}

原HTML代码

<div class="container">
  <table>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
    <tr><td>Cell</td></tr>
  </table>
</div>

为什么我的演示无法正常运行?原演示在Edge浏览器调试器中,悬停可视区域外的行时会显示“Descendants are skipped due to content-visibility”提示框,但我的演示中没有这个提示。我哪里操作有误?我正在尝试理解这个新CSS属性。


更新说明

我最终通过CSS将表格改为grid布局后使其生效。看来content-visibility在原生表格元素上无法正常工作🤷。

修改后的CSS代码

.container {
  height: 100px;
  border: 1px solid #000;
  contain: strict;
  contain-intrinsic-height: 100px;
  overflow: auto;
}
table,
tbody {
  display: block;
}
tr {
  contain: strict;
  contain-intrinsic-height: auto 21px;
  content-visibility: auto;
  display: grid;
}

内容的提问来源于stack exchange,提问作者jesterly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 10:12:24