Is there a way to set the text alignment of entire column in a table?

Misha Moroshko picture Misha Moroshko · Dec 16, 2010 · Viewed 53k times · Source

Is there a simple way to set the text alignment of all cells in the second column to right?

Or is the only way is to set the alignment for each cell in the column?

(Unfortunately, the align attribute of the col tag is not supported in Firefox.)

Answer

alex picture alex · Dec 16, 2010

Add a class to every cell in the 2nd column.

.second {
   text-align: right;
}

You could also use CSS3.

tr td:nth-child(2) { /* I don't think they are 0 based */
   text-align: right;
}

(It won't work in <= IE8)