Using CSS how to change only the 2nd column of a table
Using css only, how can I override the css of only the 2nd column of a table.
I can get to all of the columns using:
.countTable table table td
I can not get to the html on this page to modify it since it is not my site.
Thanks.
You can use the :nth-child
pseudo class like this:
.countTable table table td:nth-child(2)
Note though, this won't work in older browsers (or IE), you'll need to give the cells a class or use javascript in that case.
Try this:
.countTable table tr td:first-child + td
You could also reiterate in order to style the others columns:
.countTable table tr td:first-child + td + td {...} /* third column */
.countTable table tr td:first-child + td + td + td {...} /* fourth column */
.countTable table tr td:first-child + td + td + td +td {...} /* fifth column */
To change only the second column of a table use the following:
General Case:
table td + td{ /* this will go to the 2nd column of a table directly */
background:red
}
Your case:
.countTable table table td + td{
background: red
}
Note: this works for all browsers (Modern and old ones) that's why I added my answer to an old question