i'm looking at the W3Schools demo of using the <COL>
element to align columns:
<table width="100%" border="1">
<col align="left" />
<col align="left" />
<col align="right" />
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
</table>
And browser's rendering of it is not encouraging:
Chrome (10.0.648.127):
FireFox (3.6.8):
Internet Explorer 9 (standards mode):
Internet Explorer 8 (standards mode):
Internet Explorer 7 (standards mode):
Internet Explorer (quirks mode):
It's interesting to note that <COL align>
used to work in browsers, and the feature was taken away in ie8. (And Chrome, with position of being the arbiter of all things perfect, doesn't support it.)
This makes me wonder if <COL align>
is something that's not supposed to work.
Has <COL align>
been deprecated?
i understand that it hasn't been formally deprecated. But the fact that browsers used to support it, then stopped supporting it makes me believe that there is some historical story that i'm missing. i assume the intentional removal of col align
support from IE, and the continued lack of support from other browsers, indicates something is going on.
i was mistakenly assuming lack of support for all features of <COL>
meant <COL>
itself isn't supported. i mistakenly assumed that since the only attribute i was trying wasn't working: that the element wasn't working. This was my mistake; and in hindsight i should have asked if "COL align" is deprecated (which it is).
In my defense i assumed an example would have been shown what wasn't working "anymore".
<col>
tagcol
elementAs noted earlier, HTML 4 deprecated the align attribute, which was previously used to align text, tables, cell contents, other objects, and position captions. CSS replaces this with the text-align property for text.
The align attribute is not valid on div or most other tags in HTML5. It was valid markup back in HTML 3.2 and earlier, but while still works, has been invalid syntax for many years in HTML4, XHTML or HTML5.
This tag has been deprecated in HTML 4 (and XHTML 1) in favor of the CSS text-align property, which can be applied to the <div> element or to an individual <p> .
Set a to zero and b to the position of the column in the table, e.g. td:nth-child(2) { text-align: right; } to right-align the second column. If the table does use a colspan attribute, the effect can be achieved by combining adequate CSS attribute selectors like [colspan=n] , though this is not trivial.
Yes, the align
attribute of <col />
no longer appears in HTML5. Says the spec!
Also, it's worth noting that you can't achieve a similar result using CSS on the <col />
tag. The style
attribute (or induced style from id
, class
, etc.) only takes into account properties that sensibly apply to the column itself. That is, while each <td />
can contain text content and thus can have attributes like text-align
set, the <col />
element does not contain text and thus none of the text-level styles apply. (Block-level stuff like background-color
still works.)
However, in basic cases not involving colspan
or rowspan
, you can select blocks of <td />
s (and thus "columns" in a sense) by using the CSS pseudo-class :nth-of-type
. E.g. to center the third column of the table with class c3
use
table.c3 td:nth-of-type(3) { text-align: center; }
Edit by OP:
From The HTML Standard:
15 Obsolete features
15.2 Non-conforming featuresThe following attributes are obsolete (though the elements are still part of the language), and must not be used by authors: ...
align on col elements
...Use CSS instead.
The WHATWG wiki gives some recommended alternatives for various obsolete presentational attributes:
Attribute CSS equivalent ===================== ===================================== align on col elements 'text-align' on the appropriate td/th
Try
<!doctype html>
<html>
<head>
<title>Table</title>
<style>
table.foo td:nth-of-type(2) {
font-style: italic;
}
</style>
</head>
<body>
<table class="foo">
<thead>
<tr> <th>first</th> <th>second</th> </tr>
</thead>
<tbody>
<tr> <td>bar</td> <td>baz</td> </tr>
<tr> <td>bim</td> <td>buh</td> </tr>
</tbody>
</table>
</body>
<html>
Which renders as:
The <col>
tag is not deprecated.
See: How to use <col> tag correctly and is it supported in all browser? I think this answer clarifies its usage, and explains some of the trouble you are having with it.
It is part of XHTML and HTML 5. http://www.tutorialspoint.com/html5/html5_tags.htm
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