I've just ran into a use case where it would be useful to style a col
tag:
In this particular case I wanted to set the color
of the "Post Name" column but it turns out that it doesn't work or it is not allowed. But background-color
is allowed though which makes me wonder why color
is not.
I've checked the spec (http://www.w3.org/TR/html5/tabular-data.html#the-col-element) but I couldn't find any useful information. I know how to do the same effect with CSS only, I just wonder if anyone knows the reason why this happens to be like that?
Example: http://jsfiddle.net/nunoarruda/d8d7rans/
The <col> tag specifies column properties for each column within a <colgroup> element. The <col> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row.
<col>: The Table Column element. The <col> HTML element defines a column within a table and is used for defining common semantics on all common cells. It is generally found within a <colgroup> element.
Take a look at the diagram at CSS 2.1 spec, 17.5.1 Table layers and transparency
Columns are a layer in the rendering. so backgrounds of the layers above show through to the columns layer by default. Text on the other hand only applies to the cell, so only it can set the text color. Text color inherits by default though, so the cell can acquire its text color from an ancestor element. Col elements are never ancestors of cells.
The properties for which columns' properties apply are listed at CSS 2.1 spec, 17.3 Columns
If you can use CSS3:
table tr td:nth-child(2) {
color: #CC0000;
}
That sets the color of every second <td>
in a <tr>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With