table, td, th {
border: 1px solid black;
}
table {
width: 100%;
}
th {
height: 50px;
}
td:last-child {
text-align: right;
}
<table>
<tr>
<th idx="0"><div>Firstname</div></th>
<th idx="1"><div>Lastname</div></th>
<th idx="2"><div>Savings</div></th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
<td>$100</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
<td>$150</td>
</tr>
<tr>
<td>Joe</td>
<td>Swanson</td>
<td>$300</td>
</tr>
<tr>
<td>Cleveland</td>
<td>Brown</td>
<td>$250</td>
</tr>
</table>
What I need is, if the table heading is Savings then I need to target the idx=2 using css attribute selector like table th[idx="2"] {text-align: right;}
but the problem here is the heading values are variable. This value i.e. Savings in the heading can be anywhere in the header so I need to select based on the values. Any solutions based on CSS? If not from CSS then possibly JavaScript?
Many thanks.