[英]Wrapper for multiple <tbody>?
For specific css requirements I'm using multiple <tbody>
tags in my table design which looks something like this: 对于特定的CSS要求,我在表设计中使用了多个
<tbody>
标记,如下所示:
Use of multiple tbody tags 使用多个肢体标签
But I also require a wrapper for multiple tbody tags (something like a common tbody parent) such that this wrapper can be scrolled in order achieve the following effect: 但是我还需要多个tbody标签的包装器 (类似于常见的tbody父级),以便可以滚动此包装器以实现以下效果:
A common tbody which can be scrolled 可以滚动的常见琴体
How do I achieve the latter srolling effect in the former one? 如何在前者中实现后者的滚动效果?
(PS: I know this can be done through nested table approach, but I'm looking for other alternatives if any) (PS:我知道这可以通过嵌套表方法完成,但是我正在寻找其他替代方法)
You cannot have a wrapper for tbody
elements inside a table. 您不能在表中包含用于
tbody
元素的包装器。 The tbody
element itself is a wrapper for tr
elements. tbody
元素本身是tr
元素的包装。 HTML syntax does not allow any other container for tbody
but table
. HTML语法不允许
tbody
允许使用任何其他容器,但table
tbody
。 What matters more is that this syntax rules is actually enforced by the way browsers parse HTML. 更重要的是,此语法规则实际上是由浏览器解析HTML的方式实施的。
If you try to use, say, a div
element as a wrapper (the most reasonable approach), it will actually create a div
element in the DOM, but an empty one, and before the table. 如果您尝试使用
div
元素作为包装器(最合理的方法),它将实际上在DOM中创建一个div
元素,但在表之前是一个空元素。 All the tbody
and tr
elements are inserted into the table
element; 所有的
tbody
和tr
元素都插入到table
元素中; they are effectively extracted from the div
element, which thus becomes empty, unless it contains something else than table-related elements. 它们是有效地从
div
元素中提取的,因此div
元素为空,除非它包含与表相关的元素以外的其他内容。
An illustration, using intentionally invalid markup: 一个示例,使用故意无效的标记:
<style> .x { outline: solid red } </style> <table> <tbody> <tr><td>foo </tbody> <div class=x> FOO! <tbody> <tr><td>foo2 </tbody> <tbody> <tr><td>foo3 </tbody> </div> <tbody> <tr><td>The end </tbody> </table>
The conclusion is that you need a different approach. 结论是您需要一种不同的方法。 The most obvious one is to use just a single
tbody
element. 最明显的是只使用一个
tbody
元素。 If this is not feasible, you should explain why, but this would be a topic for a new question. 如果这不可行,则应解释原因,但这将是一个新问题的主题。
As mentioned in the comments by FelipeAls and others that a <tbody>
tag can be wrapped only by a <table>
tag, I tried wrapping <thead>
and <tbody>
s in separate tables to create the desired effect in the following way: 正如FelipeAls和其他人的评论中提到的那样,
<tbody>
标记只能由<table>
标记包装,我尝试将<thead>
和<tbody>
包裹在单独的表中,从而通过以下方式创建所需的效果:
<table>
<thead>
...
</thead>
</table>
<table>
<tbody>
...
</tbody>
<tbody>
...
</tbody>
<tbody>
...
</tbody>
</table>
This solved the issue. 这解决了问题。
Here's a Working Demo . 这是一个工作示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.