使用nth-child()进行高级元素选择

时间:2014-01-25 17:12:52

标签: html css css3 css-selectors

我对nth-child选项有点问题。我需要获得下一个数字系列才能应用一种风格:

3,4,7,8,11,12,15,16,...

the idea is set the white background of the elements

我的解决方案是使用两个css规则:

.info div:nth-of-type(4n+4),
.info div:nth-of-type(4n-1)

但我想知道是否可以只使用一个选择器。

1 个答案:

答案 0 :(得分:2)

是的,您可以使用

div:not(:nth-child(4n+1)):not(:nth-child(4n+2))

但在我看来,原始版本更具可读性。

相关问题