nth-child with mod (or modulo) operator(带有 mod(或模)运算符的 nth-child)
问题描述
是否可以将 nth-child
与模一起使用?我知道你可以指定一个公式,比如
Is it possible to use the nth-child
with modulo? I know you can specify a formula, such as
nth-child(4n+2)
但我似乎无法找到是否有模运算符.我已经尝试了以下示例,但似乎都不起作用:
But I can't seem to find if there's a modulo operator. I've tried the following examples below, and none seem to work:
nth-child(n%7)
nth-child(n % 7)
nth-child(n mod 7)
推荐答案
不,:nth-child()
只支持加减法和系数乘法.
我猜你正在尝试获取前 6 个元素(因为任何正整数 n
的 n mod 7
只会给你 0
到 6
).为此,您可以改用以下公式:
I gather you're trying to pick up the first 6 elements (as n mod 7
for any positive integer n
only gives you 0
to 6
). For that, you can use this formula instead:
:nth-child(-n+6)
通过否定n
,元素计数从零开始倒数,所以这些元素会被选中:
By negating n
, element counting is done backwards starting from zero, so these elements will be selected:
0 + 6 = 6
-1 + 6 = 5
-2 + 6 = 4
-3 + 6 = 3
-4 + 6 = 2
-5 + 6 = 1
...
jsFiddle 演示
这篇关于带有 mod(或模)运算符的 nth-child的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 mod(或模)运算符的 nth-child


- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07