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)
No,
:nth-child()only supports addition, subtraction and coefficient multiplication.I gather you’re trying to pick up the first 6 elements (as
n mod 7for any positive integernonly gives you0to6). For that, you can use this formula instead:By negating
n, element counting is done backwards starting from zero, so these elements will be selected:jsFiddle demo