Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
888 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you want to use nth-child with modulo k, just specify:

nth-child(kn)

For example, if you want to specify style for 3, 6, 9, .. elements, just specify (k = 3), and use:

nth-child(3n)

You can also specify an offset:

nth-child(kn+offset)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...