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

标签 html css 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)

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

最佳答案

是的,你可以使用

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

但我认为原始版本更具可读性。

关于html - 使用 nth-child() 进行高级元素选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21353536/

相关文章:

html - 我的 css 下拉菜单不会显示子菜单

javascript - Google map 和 100% 高度有问题吗?

javascript - 使用固定元素和调整大小的 HTML CSS

javascript - 用于隐藏具有类的子元素的元素的 Jquery 选择器

html - CSS 选择器 : Possible to select ONLY the second element?

html - 内联 CSS 电子邮件 CTA 按钮未出现在 Outlook Office 365 中 为什么?

javascript - 如何使用 JavaScript/jQuery 选择图像的多边形区域?

html - 如何仅使用类 "box special"而不仅仅是 "box"开始对第 n 个子选择器进行计数?

javascript - onclick 仅适用于 img 标签

html - 在 div 容器中带有滚动条的 CSS 网格