对于 CSS3,我知道我可以使用 nth-child(an + b)
选择器。我有一个包含 5 行的表,我想用一个语句选择第 1、2、4 和 5 行。这是可能的还是我必须至少使用两个这样的语句:
:nth-child(-n+2) /* gets 1 and 2 */
:nth-child(n+4) /* gets 4 and 5 */
我希望使用像 nth-child(1,2,4,5)
或 nth-child(1-2,4-5)
这样的语法,但是它似乎不是规范的一部分。
(我无法控制页面,这些行上没有 ID/类。)
最佳答案
如果你想明确一点,一种方法是像这样重复 :nth-child()
:
tr:nth-child(1), tr:nth-child(2), tr:nth-child(4), tr:nth-child(5)
或者,由于表格恰好有 5 行,您可以只排除第三行,您将得到行 #1、#2、#4 和 #5:
tr:not(:nth-child(3))
关于CSS nth-child - 一次获得第一个、第二个、第四个和第五个 child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5160008/