Better way to right align text in HTML Table

前端 未结 11 2178
无人及你
无人及你 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:01

    You could use the nth-child pseudo-selector. For example:

    table.align-right-3rd-column td:nth-child(3)
    {
      text-align: right;
    }
    

    Then in your table do:

    
        ...
      

    Edit:

    Unfortunately, this only works in Firefox 3.5. However, if your table only has 3 columns, you could use the sibling selector, which has much better browser support. Here's what the style sheet would look like:

    table.align-right-3rd-column td + td + td
    {
      text-align: right;
    }
    

    This will match any column preceded by two other columns.

提交回复
热议问题