Style the first column of a table differently

后端 未结 5 717
清歌不尽
清歌不尽 2020-12-25 09:19

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

5条回答
  •  爱一瞬间的悲伤
    2020-12-25 09:54

    The :nth-child() and :nth-of-type() pseudo-classes allows you to select elements with a formula.

    The syntax is :nth-child(an+b), where you replace a and b by numbers of your choice.

    For instance, :nth-child(3n+1) selects the 1st, 4th, 7th etc. child.

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

    :nth-of-type() works the same, except that it only considers element of the given type ( in the example).

提交回复
热议问题