tags:

views:

40

answers:

3

Is there a way to select one whole column in a table to style differently? without adding class or id to all those td?

I want to do with HTML and css 2.1 only. with cross browser compatibility

+4  A: 

You could try to use <col> element.

Rubens Farias
Yup, although I think the only CSS properties you can set for table cells using the `<col>` element are `border`, `background`, `width` and `visibility`. And I don’t know how well they’re supported.
Paul D. Waite
In that link they talks about browser support
Rubens Farias
@Rubens Farias - I think <col> is not supported by Firefox.
metal-gear-solid
+2  A: 

You can select a column in a table by using jQuery cell selector plugin. Here is the example:

$('#mytable tbody td:nth-col(4)');

This code shows how to select the fourth column of a table.

HTH

Pavel Nikolov
A: 

I think recent versions of Safari, Opera and Firefox support the :nth-child CSS selector, so that’s another option.

I don’t think IE 6 and 7 will give you any joy though, you’re stuck with adding classes to the <td>s there.

Paul D. Waite