7

我目前有这个很长的规则

#content #wrapper table td:nth-child(3), 
#content #wrapper table td:nth-child(4), 
#content #wrapper table td:nth-child(5) {
     width: 30px;
}

是否可以将第 n 个孩子组合成更短的东西,nth-child(3,4,5)而不是 3 条单独的线?

4

5 回答 5

7

这应该可以解决问题:

#content #wrapper table td:nth-child(n+3):nth-child(-n+5) {
    width: 30px;
}
于 2013-03-05T20:59:14.990 回答
1

不直接基于您的代码,但这应该给您一个想法。

ul li:nth-child(n+3):nth-child(-n+7){ }
于 2013-03-05T20:58:34.253 回答
1
a:nth-child(4),+:nth-child(5){color:red}
于 2022-01-16T10:54:13.253 回答
0

你可以试试

#content #wrapper table td:nth-child(n+3)

这将选择除前 2 个之外的所有内容。

来自:http : //css-tricks.com/useful-nth-child-recipies/

于 2013-03-05T20:58:34.947 回答
-3

并不是说我知道我害怕。如果您正在寻找更少的代码以使其更易于维护,您可以尝试类似 SASS 的东西。

于 2013-03-05T20:57:35.093 回答