Style the first <td> column of a table differently

Shalin picture Shalin · Mar 28, 2013 · Viewed 106.1k times · Source

If I have a table with two columns, how do I specify a padding or any other css so that it is applied just for the first column of <td>s. Also how do I style an n-th column similarly?

Answer

RRikesh picture RRikesh · Mar 28, 2013

You could use the n-th child selector.

to target the nth element you could then use:

td:nth-child(n) {  
  /* your stuff here */
}

(where n starts at 1)