:nth-of-type(n) "n"计数器是否在同一 CSS 规则中与其他计数器独立递增?



在:n -of-type() CSS选择器中n个计数器是否相互独立地递增?例如,如果我想要label:checked:n -of-type(3)来匹配它的一般同胞article:n -of-type(3),这种技术应该起作用吗?(它没有,但也许我只是想确定。)

label:checked:nth-of-type(n) ~ article:nth-of-type(n)

不需要明确地说:n -of-type(1),:n -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 */
}

…这是一种痛苦。我明白你的意思了,如果能使用这样的东西就太棒了!

最新更新