gsi*_*011 48 css css-selectors
除了第一个和最后一个,我如何选择表格中的所有孩子?我已经尝试了这个,但它最终选择了所有不是第一个的孩子和所有不是最后的孩子,最终成为所有孩子:
table.programs tr td:not(:first-child), table.programs tr td:not(:last-child) {
}
Run Code Online (Sandbox Code Playgroud)
我想要所有既不是第一个也不是最后一个的孩子.我怎样才能做到这一点?
Juk*_*ela 68
使用两个:not()选择器组合,从而引用与它们相匹配的元素,即与既不匹配用作以下操作数的选择器的元素:not():
table.programs td:not(:first-child):not(:last-child)
Run Code Online (Sandbox Code Playgroud)
jQuery 解决方案很好,但如果你想用纯 CSS 来做,我建议你将规则应用于整个表格,然后为第一个和最后一个孩子重置它们。IE:
table.programs tr td {
/* your rules here */
}
table.programs tr:first-child td:first-child,
table.programs tr:last-child td:last-child {
/* reset your rules here */
}
Run Code Online (Sandbox Code Playgroud)
我认为这应该对你有用:
table.programs tr td:not(:first-child,:last-child)
Run Code Online (Sandbox Code Playgroud)