【问题标题】:CSS selector for other than the first child and last child第一个孩子和最后一个孩子以外的 CSS 选择器
【发布时间】:2011-12-08 22:28:20
【问题描述】:

我正在制作一个非常先进的网站。我的问题:是否可以选择除:first-child:last-child 之外的所有其他孩子?我知道有一个:not() 选择器,但它不适用于括号中没有的多个选择器。这就是我所拥有的:

#navigation ul li:not(:first-child, :last-child) {
    background: url(images/UISegmentBarButtonmiddle@2x.png);
    background-size: contain;
}

【问题讨论】:

  • 你很勇敢地使用它。请注意,它只适用于现代浏览器,绝对不会适用于每个人都在使用的反浏览器。
  • @Radu:“我正在制作一个非常先进的网站”这并不奇怪......
  • @BoltClock,对,只是说......警告的话。但无论如何,如果目标是图像名称所暗示的 iOS Safari,那么它应该是安全的。
  • 现在我明白为什么这个问题看起来如此熟悉了...stackoverflow.com/questions/7403129/combining-not-selectors
  • “反浏览器”?这就是我一直听说的新 Google Ultron 吗?

标签: html css css-selectors


【解决方案1】:

试试:

#navigation ul li:not(:first-child):not(:last-child) {
  ...
}

【讨论】:

  • rofl,我的愚蠢not() 甚至在谷歌搜索之前尝试过这个:P 天才
  • 错了:not (A and B) 不等于(not A) and (not B),而是(not A) or (not B)。它不起作用。
  • 不,萨尔曼·阿巴斯说的是对的。你在想逗号; #navigation ul li:not(:first-child), #navigation ul li:not(:last-child)
【解决方案2】:

当然可以,您只需要使用两个“非”选择器。

#navigation ul li:not(:first-child):not(:last-child) {

它将在第一个孩子之后继续下去,说“不是第一个孩子”和“不是最后一个孩子”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-12
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多