Search code examples
csscss-selectorspadding

Style the first <td> column of a table differently


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?


Solution

  • 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)