CSS如何使用伪类:not with:nth-child [英] CSS how to use pseudo-class :not with :nth-child
问题描述
是否可以使用:not()
和 nth-child
?
我没试过这样的运气:
td:not(:nth-child(4n)){
text-align:center;
}
但这似乎可以工作:
td:not(:first-child){
text-align:center;
}
我想要的是中心对齐所有表格列。
What I am trying is to center align all table columns except 2nd and 4th column. The columns are dynamically generated to add a custom class to these column .
推荐答案
:not(:nth -child(4n))
会得到不是:nth-child(4n)
的任何东西, ,8th等。它不会排除第二个孩子,因为2不是4的倍数。
: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))
6列或
td:not(:nth-child(2)):not(:nth-child )
,如果您有至少6列,并且只想排除第2和第4,而不是每个偶数列。
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.
这篇关于CSS如何使用伪类:not with:nth-child的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!