Is there a way to center specific columns in a table?

I make extensive use of css formatting and define a class for a table with subclasses for thead, tbody, tfoot and another level of subclasses for tr, th, td ....

In some cases, I want the entire column of the table to have a class with a specific style ... but I don't know how to do it.

Is there a way (using HTML5, css3, something else?) So that all cells in a specific tbody column have the same class?

I can specify the class explicitly (manually), but I would like to avoid such duplication.

Any thoughts are welcome.

PS I guess I should not worry about this and just specify a class for each cell?

+2
source share
2 answers

- nth-child css .

:

#myTable tr td:nth-child(3) {
  text-align: center;
}

, X . "n" n- . http://css-tricks.com/how-nth-child-works/ .

+1

All Articles