Html 表中的多个 <thead>/<tbody> 是否有效?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16155396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple <thead>/ <tbody> in Table Valid?
提问by AlbertEngelB
Imagine a list of lists similar to this:
想象一个类似这样的列表:
var list = [
{ name: 'group1',
items: [ 1, 2, 3, 4, 5 ]
},
{ name: 'group2',
items: [ 1, 2, 3, 4, 5 ]
},
etc...
]
Now forgetting the whole "tables are for data not design" argument, I wanted to display a single table for list
and have a seperate <thead>
and <tbody>
for each entry in list
.
现在忘记了整个“表数据没有设计”的说法,我想显示一个表list
,并有一个单独的<thead>
,并<tbody>
在每个条目list
。
Is this technically valid? This works in the browser, but my spider senses are tingling on this one.
这在技术上有效吗?这在浏览器中有效,但我的蜘蛛感觉对这个感到刺痛。
回答by Jon
You can have as many <tbody>
elements as you want, but no more than one each of <thead>
and <tfoot>
. Reference:
您可以拥有任意数量的<tbody>
元素,但<thead>
和 中的每个元素不超过一个<tfoot>
。参考:
Content model:
In this order: optionally a caption element, followed by zero or more colgroup elements, followed optionally by a thead element, followed by either zero or more tbody elements or one or more tr elements, followed optionally by a tfoot element, optionally intermixed with one or more script-supporting elements.
内容模型:
按此顺序:可选的标题元素,后跟零个或多个 colgroup 元素,可选地后跟一个 thead 元素,后跟零个或多个 tbody 元素或一个或多个 tr 元素,后跟可选的 tfoot 元素,可选地与一个混合或更多脚本支持元素。
回答by Zeta
There's at most one thead
and one tfoot
allowed, so you shouldn't create additional headers. After all the th
in a thead
gives a meaning to your columns, like "time of day", "temperature", "amount of cats currently on fire".
最多有一个thead
和一个tfoot
allowed,所以你不应该创建额外的标题。毕竟th
in athead
为您的列赋予了含义,例如“一天中的时间”、“温度”、“当前着火的猫数量”。
If the entries in your list are related they should all be in the same table and you should provide a fitting header to display that relation.
如果列表中的条目相关,它们应该都在同一个表中,并且您应该提供一个合适的标题来显示该关系。
If the entries are actually unrelated you should provide a single table for every of those. You can still apply the same CSS on every table to get a nice result.
如果条目实际上不相关,您应该为每个条目提供一个表格。您仍然可以在每个表上应用相同的 CSS 以获得不错的结果。
回答by Justin
I consider it to be just like id
attributes. They are supposed to be unique, but you can actually re-use it in the same page and you can still select it. That said, just because it can be done doesn't mean it should be done.
我认为它就像id
属性一样。它们应该是独一无二的,但您实际上可以在同一页面中重复使用它,并且您仍然可以选择它。 也就是说,仅仅因为它可以完成并不意味着它应该被完成。
I would recommend against it.
我会建议反对它。