andand <...">

Span attribute for colgroup and col

Are these codes logically equivalent?

<colgroup span="7"> </colgroup> 

and

 <col span="7" /> 

and

 <colgroup> <col /> <col /> <col /> <col /> <col /> <col /> <col /> </colgroup> 

Will there be the same effects of any attributes through HTML or properties through CSS? Can anyone add the tag "colgroup". I do not have enough reputation for this.

+2
source share
2 answers

From the specification for <col> :

Contexts in which this element can be used:
As a child of colgroup that does not have a span attribute.
[...]
Content Attributes: Global Attributes
range

I read that saying that only <col span="7" /> is not valid in itself, but this:

 <colgroup> <col span="7" /> </colgroup> 

valid and matches:

 <colgroup span="7"> </colgroup> 

However, if <colgroup> has a span attribute , it should not have <col> children:

If the colgroup element does not contain col elements, then the element may have a range content attribute specified ...

My interpretation (based on the HTML4 specification more than thinner HTML5) is that you usually use <colgroup span="n"> unless you need to enter one of the columns in a group differently, like this one (modified ) example from HTML4 specification:

 <colgroup style="width: 20px; font-weight: bold;"> <col span="39"> <col id="format-me-specially" style="width: 35px;"> </colgroup> 

therefore, the first 39 columns will use whatever <colgroup> specified, but the 40th can be changed. OTOH, I'm having problems getting browsers to pay much attention to any of these (despite what specs say) on jsfiddle.net, so YMMV.

+3
source

Here is my interpretation of the specifications. Update: colgroup looking at the HTML4 specifications, I changed my mind about the colgroup element span attribute.

(This is also in response to my own second question in a @mu comment.)

A colgroup represents a group of one or more columns and its span indicates the number of columns in the column group . Therefore, I consider this a shortcut, keeping the author from writing several col elements in a row.

 <colgroup class="x" span="3"></colgroup> 

(you cannot write <colgroup class="x" span="3" /> for some silly reason)

A group of columns spans three columns and is styled according to the CSS .x {...} rule. It is equivalent

 <colgroup class="x"> <col /> <col /> <col /> </colgroup> 

On the other hand, col represents one or more columns in a group of columns, and its span indicates the number of columns "stretched" by the col element ... this is a circular definition, if you ask me.

The only way I can interpret this is to write

 <colgroup class="x"><col class="y" span="3" /></colgroup> 

you say that there are three columns, each in the same logical group, in the same style, according to .y {...} . This is a shortcut for recording.

 <colgroup class="x"> <col class="y" /> <col class="y" /> <col class="y" /> </colgroup> 

Presentationally, I'm not sure there will be a noticeable difference. Of course, it all depends on your CSS. But semantically they are very different. The first example represents three groups of columns with each group containing one column, while the second example represents one group of three columns.

Rethinking this, I decided that they are both the same. The number of colgroup span n columns matches the number of colgroup with the col child that spans n columns. In my opinion, there is no logical or semantic difference.

Note: The col element must be contained in a colgroup element that does not have a span attribute. It cannot be a direct child of table .

+1
source

Source: https://habr.com/ru/post/1397681/


All Articles