colgroup 和 col 上的 Span 属性
这些代码在逻辑上是等价的吗?
<colgroup span="7">
</colgroup>
并且
<col span="7" />
?
<colgroup>
<col />
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
通过 HTML 的任何属性或通过 CSS 的属性是否具有同等效果 有人还可以添加“colgroup”标签吗?没有足够的代表让我这么做。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自
规范
:
是
本身是无效的,但这:
是有效的并且与:
但是,如果
有一个
span< /code> 属性
,那么它应该没有
孩子:
我的解释(基于 HTML4 规范 比更薄的 HTML5 规范更多)是您通常会使用
除非您需要设计其中之一的样式组中的列与 HTML4 规范中的(修改后的)示例不同:
因此前 39 列将使用
指定的任何内容,但第 40 列可以进行调整。 OTOH,我很难让浏览器对 jsfiddle.net 上的所有这些(不管规范怎么说)给予太多关注,所以 YMMV。
From the specification for
<col>
:I read that as saying that just
<col span="7" />
on its own is invalid but this:is valid and the same as:
However, if the
<colgroup>
has aspan
attribute, then it should not have<col>
children:My interpretation (based on the HTML4 specification more than the thinner HTML5 one) is that you would usually use
<colgroup span="n">
unless you needed to style one of the columns in the group differently as in this (modified) example from the HTML4 specification:so the first 39 columns would use whatever the
<colgroup>
specifies but the 40th could be tweaked. OTOH, I'm having trouble getting browsers to pay much attention to any of this (despite what the specs say) on jsfiddle.net so YMMV.这是我对规格的解释。 更新:在查看 HTML4 规范后,我改变了对
colgroup
元素的span
属性的看法。(这也是为了回应我自己在@mu的回答中评论了第二个问题。)
colgroup
代表一个 一组或多列及其span
指定列组中的列数。所以我认为它是一种快捷方式,使作者免于连续编写多个col
元素。列组跨越三列,并根据 CSS 规则
.x {...}
设置样式。这相当于另一方面,
col
代表 列组中的一个或多个列,及其span
指定COL 元素
...如果你问我的话,这是一个循环定义。我可以解释这一点的唯一方法是,通过编写,
您可以说有三列,每列都在相同的逻辑分组中,根据
.y {...}
具有相同的样式。这是编写的快捷方式。目前,我不确定是否会有明显的差异。当然,它的外观取决于你的 CSS。但从语义上来说,它们有很大不同。第一个示例表示三组列,每组包含一列,而第二个示例表示一组三列。
经过重新思考,我认为它们是相同的。拥有一个
colgroup
跨越n
列与拥有一个colgroup
以及一个跨越col
子级的colgroup
是一样的代码>n列。我认为不存在逻辑或语义差异。注意:
col
元素必须包含在没有span
属性的colgroup
元素中。它可能不是table
元素 的直接子元素。Here’s my interpretation of the specs. Update: After looking at the HTML4 specs, I’ve changed my mind about the
colgroup
element'sspan
attribute.(This is also in response to my own 2nd question comment in @mu’s answer.)
A
colgroup
represents a group of one or more columns, and itsspan
specifies the number of columns in a column group. So I think of it as a shortcut, saving the author from writing multiplecol
elements in succession.The column group spans over three columns and is styled according to the CSS rule
.x {...}
. This is equivalent toOn the other hand,
col
represents one or more columns in the column group, and itsspan
specifies the number of columns "spanned" by theCOL
element… which is a cyclical definition if you ask me.The only way I can interpret this is that by writing
you’re saying there are three columns, each in the same logical grouping, styled the same way according to
.y {...}
. This is a shortcut to writingPresentationally, I’m not sure there would be a noticeable difference. How it all looks depends on your CSS of course. But semantically, they are very different. The first example represents three groups of columns with each group containing one column, whereas the second example represents one group of three columns.After rethinking this, I’ve decided that they’re both the same. Having a
colgroup
spann
number of columns is the same as having onecolgroup
with acol
child that spansn
columns. There is no logical or semantic difference in my opinion.Note: the
col
element must be contained in acolgroup
element that has nospan
attribute. It may not be a direct child of thetable
element.