0

Would it be possible to write CSS to select elements where their n is equal to the n of another element in the same selector:

input:nth-child(1):checked ~ div > div:nth-child(1)
input:nth-child(2):checked ~ div > div:nth-child(2)
input:nth-child(3):checked ~ div > div:nth-child(3)
...
input:nth-child(n):checked ~ div > div:nth-child(n)

Does CSS support this capability, or would everything have to be written out line-by-line?

ban_javascript
  • 157
  • 1
  • 5
  • 12

1 Answers1

1

Selectors doesn't support variables or backreferences of any kind, in either attribute selectors (1 2) or functional pseudo-classes such as :nth-child(). You cannot use custom properties in selectors either.

As with attribute selectors in the first two links above, you can use a preprocessor to automate this but the resulting CSS file will still contain a hardcoded list of all the possibilities.

BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328