Is html <COL align> deprecated?
Asked Answered
D

6

24

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):
enter image description here

FireFox (3.6.8):
enter image description here

Internet Explorer 9 (standards mode):
enter image description here

Internet Explorer 8 (standards mode):
enter image description here

Internet Explorer 7 (standards mode):
enter image description here

Internet Explorer (quirks mode): enter image description here

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?


Update One

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.

Update Two

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".

See also

Downstage answered 10/3, 2011 at 14:59 Comment(9)
keep in mind that w3school has nothing to do with w3c!Obliquely
@Tobiask This is true. But showing people an example, that isn't my own code, is helpful as an independent test.Downstage
might be true, just wanna to make that clear :)Obliquely
w3fools.com please read!Superscription
@Superscription That's an interesting rant site. Is anything wrong with the HTML source quoted in the question?Downstage
@Ian: yes; in HTML5 <col /> elements must be wrapped in <colgroup /> elements. Also, your earlier edit was missing a <!DOCTYPE html>, so it would have triggered quirks mode.Superscription
Also, I'm not sure if you meant "rant site" pejoratively or not, but it's worthwhile really reading through their list of defects to see how bad w3schools is. It's basically a SEO trap full of outdated information.Superscription
@Superscription In the end there is nothing wrong with the HTML and its use of align, except that in HTML5 align is obsolete. That is why IE stopped supporting it. And while w3fools might prefer wiki edited examples, the page (in it's lengthly list of complaints) has no quarrel with COL align. So there really isn't a need to link to it on this particular StackOverflow question: since nothing on w3fools applies. If there was a mistake in the HTML, then any correction on w3fools would be helpful. But since there wasn't: it isn't.Downstage
deprecating this attr is very stupid, because css aren't good enough col{text-align:right} does nothing, obviouslyCarlyle
S
27

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:

16 Obsolete features

[...]

16.2 Non-conforming features

The 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
Superscription answered 10/3, 2011 at 15:41 Comment(9)
Thanks for the link; i didn't actually appreciate the fact that i wasn't reading the latest HTML spec.Downstage
What a crap suggestion, "Add 'text-align' style property to every cell in that column." :/Stowage
@antisanity i agree that removal of align is, in my opinion, a mistake.Downstage
Unfortunately, nth-of-type is obviously totally buggy in current browsers. The rule destroys other, unrelated layout once it’s present in the CSS, even if it hasn’t got any styles applied.Dorsoventral
@Superscription It clashed with another rule to create zebra striping, tr td:nth-child(odd) … but simplifying this rule to tr:nth-child(odd) solved the problem. But it’s still a bug.Dorsoventral
@KonradRudolph again demo? I have never had a problem with nth-child and nth-of-type interacting. I'm sure the browser vendors would appreciate small reproducible test cases they can fix.Superscription
@Superscription Which, sorry, I have no time to build now. It broke today on a biggish website I built, I fixed it with the above mentioned change but unfortunately I don’t have the time at the moment to built a small test case.Dorsoventral
I think they have cery different purposes. I am very surprised to read this. I understood that, you alight THE COLUMNS with respect to the table with the align attribute. Aligning the text of course is better with css.Entrant
td:nth-of-type(3) will not work if you are using colspan to display a cell over multiple columns.Hyozo
H
4

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:

enter image description here

Hawking answered 5/7, 2012 at 23:58 Comment(0)
P
2

Edit: This answers the original question, which used to ask about <col> itself rather than the align attribute.

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

Persuade answered 10/3, 2011 at 15:2 Comment(2)
I understood that XHTML stands, currently, at 1.1.Enravish
@David: depends what you mean by “currently”. HTML5 (which can be written using traditional HTML syntax, or XHTML syntax) isn’t a W3C Recommendation yet, but it’s what all the browser vendors are converging on, and there aren’t any competing efforts. It’s the present and future of (X)HTML.Laugh
D
0

Edit: This answers the original question, which used to ask about <col> itself rather than the align attribute.

No it has not, it is both part of the html4 spec and the html5 spec.

http://www.w3.org/TR/html401/struct/tables.html#h-11.2.4.2

http://dev.w3.org/html5/markup/col.html

http://www.html-5.com/tags/col-tag/

Dreadfully answered 10/3, 2011 at 15:3 Comment(0)
T
0

In the interest of making the markup semantically meaningful have you considered substituting your <col> tags with <colgroup>?

<col> is purely used for styling whereas <colgroup> can be used to group related columns (Perhaps this is why you intend to align two of them left?) You can then apply CSS to the various colgroups to style them accordingly.

Telethon answered 10/3, 2011 at 16:9 Comment(1)
That sounds like a fine idea, except you'll have to post your html snippet that works. i try it and browsers ignore css styling on my <colgroup class="alignTheseRight">, with .alignTheseRight { text-align: right; }Downstage
U
0

According to the second example table in the HTML spec, it’s colgroup, despite the lack of colgroup tags.

http://www.w3.org/TR/html4/struct/tables.html#h-11.4.1

Ululate answered 12/11, 2013 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.