【发布时间】:2017-06-22 14:35:10
【问题描述】:
这只发生在 Chrome 中。这是我的非常复杂代码的超级简化版本,thead(浅蓝色)顶部不应有字母(“x”、“y”、“z”)其中,因为它在 Firefox 上的渲染效果很好,但在 Chrome 上,内部的 div position relative 似乎在某种程度上超过了 thead。
表格单元格内的
position:relative是绝对必要的 看情况。
thead 如何超过 tbody?
它似乎不尊重任何 z-index。
我知道thead 呈现在它自己的层上,因为它上面声明了 transform,但为什么该层不在 tbody 之上?并且只在 Chrome 上?很奇怪。在 Google 上找不到任何关于此的内容。
table > thead {
background: lightblue;
z-index: 20;
}
td, th { padding: 2em ;}
table td:first-child > div {
position: relative;
background: lightyellow;
padding: 1em;
}
<table>
<thead style="transform: translate(0, 50px);">
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div>x</div>
</td>
<td>
<div>y</div>
</td>
<td>
<div>z</div>
</td>
</tr>
</tbody>
</table>
它应该是这样的(就像在 Firefox 上一样):
请记住,这是一个 简化 演示,其中 thead 有一个翻译,这实际上是由 JS 控制的,因为它与问题无关,所以这里不包括在内,只有硬编码的结果写成<thead style="transform: translate(0, 50px);">
我已经设法绕过了构建 HTML 的错误,因此 thead 写在 tbody 之后,但仍然不是一个很好的修复
更新
似乎我的“解决方案”将thead 移动到tbody 之后会导致一个错误的世界,同样仅在Chrome 中(像往常一样)并且当thead 时Chrome 会使用巨大的填充来渲染表格单元格节点在 DOM 中向下移动。目前,我没有看到分层问题的任何解决方案。
【问题讨论】:
标签: css google-chrome