align right in a table cell with CSS

后端 未结 4 1378
走了就别回头了
走了就别回头了 2020-12-09 00:27

I have the old classic code like this


which does what it says: it right aligns the content in the cell. So if I

4条回答
  •  余生分开走
    2020-12-09 01:00

    Don't forget about CSS3's 'nth-child' selector. If you know the index of the column you wish to align text to the right on, you can just specify

    table tr td:nth-child(2) {
        text-align: right;
    }
    

    In cases with large tables this can save you a lot of extra markup!

    here's a fiddle for ya.... https://jsfiddle.net/w16c2nad/

提交回复
热议问题