How to correctly align the last two columns of a table using CSS

I would like to align the text of the last two columns of the 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> 

Each row does not have the same number of columns, and I'm not sure how to use css: nth-child to select the last two td elements in each row.

+6
source share
1 answer

http://jsfiddle.net/BB9ty/

 th:last-child, td:last-child, th:nth-last-child(2), td:nth-last-child(2) { text-align: right; } 
+13
source

Source: https://habr.com/ru/post/958749/


All Articles