CSS how to use pseudo-class :not with :nth-child

前端 未结 2 837
南旧
南旧 2021-01-07 16:28

Is is possible to use :not() with nth-child ?

I tried something like this without any luck :

td:not(:nth-child(4n)){
  te         


        
2条回答
  •  心在旅途
    2021-01-07 16:37

    :not(:nth-child(4n)) will get you anything that isn't :nth-child(4n), i.e. anything that isn't the 4th, 8th and so on. It won't exclude the 2nd child because 2 isn't a multiple of 4.

    To exclude the 2nd and 4th you need either one of:

    • td:not(:nth-child(2n)) if you have fewer than 6 columns, or

    • td:not(:nth-child(2)):not(:nth-child(4)) if you have at least 6 columns and only want to exclude the 2nd and 4th, and not every even column.

    Demo

提交回复
热议问题