6

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

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

这个想法是不必明确地说 :nth-of-type(1)、:nth-of-type(2) 等等。

4

1 回答 1

1

对您来说不幸的是,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 */
}

......这是一种痛苦。我知道您将使用它去哪里,能够使用这样的东西会很棒!

于 2011-12-06T09:41:39.040 回答