CSS3 nth-child() 每 5 个元素重复范围

标签 css css-selectors

是否可以每 5 个元素选择一个范围的元素?我期望的是:

<ul>
   <li>Test</li>
   <li>Test</li> //this
   <li>Test</li> //this
   <li>Test</li> //this
   <li>Test</li>
   <li>Test</li>
   <li>Test</li> //this
   <li>Test</li> //this
   <li>Test</li> //this
   <li>Test</li>
</ul>

从 2 到 4,从 7 到 9,等等

提前致谢!

最佳答案

由于您的范围具有 [5 n - 3, 5 n - 2, 5 n - 1] 的形式(其中 n ≥ 1),使用如下代码:

li:nth-child(5n - 3), li:nth-child(5n - 2), li:nth-child(5n - 1) {
  color: red;
}
<ul>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
   <li>Test</li>
</ul>

关于CSS3 nth-child() 每 5 个元素重复范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35551936/

相关文章:

html - 实现时出现问题 :active in CSS Button

php - 如何在 Iframe 中重新加载附加数据

html - 响应式背景 css 图像

jquery - 在 jQuery 中查找 $(this) 选定值

python - NoSuchElementException : Message: Unable to locate element while trying to locate an element using Selenium and Python

javascript - 滚动回页面顶部时,Data-spy 不会重新突出显示 "Home" anchor

jQuery ul li 悬停效果

html - 如何划线边框内的所有链接并加粗标记段落的某些文本

css - 如何更改 WooCommerce 中结帐国家/地区选择时的悬停颜色?

css - 将 CSS 应用于对等元素之后的偶数和奇数元素(带有子标题的表格)