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

Categories

0 votes
918 views
in Technique[技术] by (71.8m points)

css - nth-child with mod (or modulo) operator

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

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

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...