简体   繁体   English

表中的多个<thead> / <tbody>是否有效?

[英]Multiple <thead>/ <tbody> in Table Valid?

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 . 这可以在浏览器中使用,但我的蜘蛛感觉正在刺痛这个

You can have as many <tbody> elements as you want, but no more than one each of <thead> and <tfoot> . 您可以拥有任意数量的<tbody>元素,但<thead><tfoot>各不能超过一个。 Reference : 参考

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元素, 后跟可选的元素,后跟零个或多个tbody元素或一个或多个tr元素,后跟可选的tfoot元素 ,可选择混合一个或更多脚本支持元素。

There's at most one thead and one tfoot allowed , so you shouldn't create additional headers. 最多允许一个thead和一个tfoot ,所以你不应该创建额外的标题。 After all the th in a thead gives a meaning to your columns, like "time of day", "temperature", "amount of cats currently on fire". 毕竟ththead给人一种意义的栏目,像“目前火量猫”,“一天中的时间”,“温度”。

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以获得良好的结果。

I consider it to be just like id attributes. 我认为它就像id属性一样。 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. 也就是说,仅仅因为它可以完成并不意味着它应该被完成。

I would recommend against it. 我会建议反对它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM