Search code examples
htmlcssfirefoxalignmentcss-tables

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


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


Solution

  • 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)