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.
For aligning columns to the left, the align-content property will set to 'flex-start'. For aligning columns to the right, the align-content property will set to 'flex-end'. For aligning columns to the extreme ends, the align-content property will set to 'space-between'.
The text-align property sets the horizontal alignment (like left, right, or center) of the content in <th> or <td>. By default, the content of <th> elements are center-aligned and the content of <td> elements are left-aligned.
HTML | <col> align Attribute left: It sets the text left-align. right: It sets the text right-align. center: It sets the text center-align. justify: It stretches the text of paragraph to set the width of all lines equal.
Use width:100% on the table and the middle column. You could also set width:100% on the last column's style and td align="right" on the last column. Then you can insert more columns in the middle while the spacing still works.
http://jsfiddle.net/BB9ty/
th:last-child,
td:last-child,
th:nth-last-child(2),
td:nth-last-child(2) {
text-align: right;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With