如何使用CSS选择器选择除第一个和最后一个以外的所有子代

编程入门 行业动态 更新时间:2024-10-27 16:34:06
本文介绍了如何使用CSS选择器选择除第一个和最后一个以外的所有子代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我如何选择表中除第一个和最后一个孩子以外的所有孩子?我已经尝试过了,但是最终选择了所有不是第一个的孩子和所有不是最后一个的孩子,最后都是所有孩子:

How would I select all the children in a table except for the first and last? I've tried this, but it ends up selecting all children that aren't first and all children that aren't last, which ends up being all children:

table.programs tr td:not(:first-child), table.programs tr td:not(:last-child) { }

我希望所有的孩子既不是第一个也不是最后一个.我该怎么办?

I want all children that are neither first nor last. How can I do this?

推荐答案

使用两个组合的:not()选择器,从而引用与它们都匹配的元素,即,与两个选择器都不匹配的元素用作:

Use two :not() selectors combined, thereby referring to elements that match both of them, i.e. to elements that match neither of the selectors used as operands of :not():

table.programs td:not(:first-child):not(:last-child)

更多推荐

如何使用CSS选择器选择除第一个和最后一个以外的所有子代

本文发布于:2023-10-28 13:53:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子代   第一个   如何使用   选择器   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!