15

I'd like to right align the text of last two columns of a table.

<table>
  <tr>
    <th>H 1</th>
    <th>H 2</th>
    <th>H 3</th>
    <th>H 4</th>
  </tr>
  <tr>
    <td rowspan='3'>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
  </tr>
  <tr>
    <td>2</td>
    <td>3</td>
    <td>4</td>
  </tr>
  <tr>
    <td>2</td>
    <td>3</td>
    <td>4</td>
  </tr>
</table>

There is not the same number of columns in each row and I'm not sure how to use css:nth-child to select the last two td items in each row.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Martlark
  • 14,208
  • 13
  • 83
  • 99

1 Answers1

27

http://jsfiddle.net/BB9ty/

th:last-child,
td:last-child,
th:nth-last-child(2),
td:nth-last-child(2) {
    text-align: right;
}
Mark Simpson
  • 2,344
  • 2
  • 23
  • 31