Html 除了第一个孩子和最后一个孩子的 CSS 选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7788018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS selector for other than the first child and last child
提问by Daniel
I am making a very advanced website. My question: Is it possible to select all the other children except for the :first-child
and the :last-child
? I know there is a :not()
selector but it doesn't work with more than one not in the parentheses. This is what I have:
我正在制作一个非常先进的网站。我的问题:是否可以选择除:first-child
和之外的所有其他孩子:last-child
?我知道有一个:not()
选择器,但它不能与多个不在括号中的选择器一起使用。这就是我所拥有的:
#navigation ul li:not(:first-child, :last-child) {
background: url(images/[email protected]);
background-size: contain;
}
回答by Salman von Abbas
Try #navigation ul li:not(:first-child):not(:last-child)
.
试试#navigation ul li:not(:first-child):not(:last-child)
。
回答by animuson
Sure it will work, you just have to use two 'not' selectors.
当然它会工作,你只需要使用两个“非”选择器。
#navigation ul li:not(:first-child):not(:last-child) {
It will continue down the line after the first one, saying "not the first child" and "not the last child".
它将在第一个之后继续下去,说“不是第一个孩子”和“不是最后一个孩子”。