本文介绍了具有mod(或模)运算符的第n子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用 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)
推荐答案
否,仅支持加法,减法和。
我收集你试图拿起前6个元素( n mod 7
任何正整数 n
只给你 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
...
这篇关于具有mod(或模)运算符的第n子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!