在 :nth-of-type() CSS 选择器中,n 个计数器是否相互独立递增?例如,如果我希望 label:checked:nth-of-type(3) 与其一般同级文章:nth-of-type(3) 匹配,这种技术是否可行? (它没有,但也许我只是想确定一下。)
label:checked:nth-of-type(n) ~ article:nth-of-type(n)
这个想法是不必明确地说 :nth-of-type(1)、:nth-of-type(2) 等等。
最佳答案
不幸的是,n
计数器在定义它的nth-of-type
中是本地的,因此您的技术将不起作用。你必须做这样的事情:
label:checked:nth-of-type(1) ~ article:nth-of-type(1),
label:checked:nth-of-type(2) ~ article:nth-of-type(2),
label:checked:nth-of-type(3) ~ article:nth-of-type(3),
label:checked:nth-of-type(4) ~ article:nth-of-type(4),
label:checked:nth-of-type(5) ~ article:nth-of-type(5), ...
{
/* definitions */
}
...这很痛苦。我知道你打算用它做什么,如果能够使用类似的东西那就太好了!
关于css - 执行 :nth-of-type(n) "n" counters increment independently with others in the same CSS rule?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8396263/