Better way to right align text in HTML Table

前端 未结 11 2066
无人及你
无人及你 2021-02-04 23:40

I have an HTML table with large number of rows, and I need to right align one column.

I know the following ways,

..

        
11条回答
  •  日久生厌
    2021-02-05 00:14

    If it's always the third column, you can use this (assuming table class of "products"). It's kinda hacky though, and not robust if you add a new column.

    table.products td+td+td {
      text-align: right;
    }
    table.products td,
    table.products td+td+td+td {
      text-align: left;
    }
    

    But honestly, the best idea is to use a class on each cell. You can use the col element to set the width, border, background or visibility of a column, but not any other properties. Reasons discussed here.

提交回复
热议问题