amp
amp

Reputation: 12352

CSS selector for last visible column of a grid

I have a column like this:

<table class="mytable">
  <tr>
    <th></th>
    <th></th>
    <th style="display:none"></th>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td style="display:none"></td>
  </tr>
</table>

What is the CSS selector to apply a custom style on the last visible column (th and td), in this case, the second one?

I'm confused with pseudo classes/pseudo elements...

Upvotes: 0

Views: 967

Answers (1)

Dissident Rage
Dissident Rage

Reputation: 2716

For the very last one:

td:last-child , th:last-child { ... }

But as noted in your comments, this cannot take inline styles into account. Another thing you can do is nth-child:

td:nth-child(1) , th:nth-child(1) { ... }

But this presupposes you will keep the same number of columns. If neither of these is suitable you're better off just assigning a class to your next-to-last column cells.

Upvotes: 1

Related Questions