Are these codes logically equivalent?
<colgroup span="7">
</colgroup>
And
<col span="7" />
And
<colgroup>
<col />
<col />
<col />
<col />
<col />
<col />
<col />
</colgroup>
Will any attributes via HTML or properties via CSS have equal effect? Can sombody also add "colgroup" Tag. No enough rep for me to do that.
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.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.(you can't write
<colgroup class="x" span="3" />
for some stupid reason)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 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.