css - 可以在 :not() pseudo-class? 内部使用 CSS 伪类吗

标签 css css-selectors

我想知道是否可以将伪类“嵌入”到彼此内部。我有一种预感,你不能,但我只是想确保我没有语法错误。

这是我正在尝试做的一个例子:

p.description { margin-bottom: 20px; }

鉴于这种风格,如果您只希望在不是最后 p.description 的比赛中发生这种情况,是否可以执行以下操作?

p.description:not(p.description:last-child)

自然地,我有两种风格,像这样:

p.description { margin-bottom: 20px; }
p.description:last-child { margin-bottom: 0; }

...但如果可以在一行中完成,那似乎很浪费。

非常感谢!

最佳答案

是的,您的问题标题:

p.description:not(:last-child)

不,问题正文中的 CSS 示例

p.description:not(p.description:last-child)

The spec says :

The negation pseudo-class, :not(X), is a functional notation taking a simple selector (excluding the negation pseudo-class itself) as an argument.

A simple selector is either a type selector, universal selector, attribute selector, class selector, ID selector, or pseudo-class.

关于css - 可以在 :not() pseudo-class? 内部使用 CSS 伪类吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5720064/

相关文章:

CSS 表格宽度规则

html - 使用 CSS 类继承引导网格系统

Javascript 按钮单击在 selenium webdriver 中不起作用

javascript - JQuery 将 div 添加到图像列表

c# - asp 默认设计样式仅出现在设计时,在运行时 visual studio 2012 中消失

html - 跟进帖子: "...why are there no “justify-items” and “justify-self” properties?“

css - Wordpress Neve 主题 - 主导航 CSS

html - Webkit 伪元素文档

javascript - 在 CSS 中每隔一个子层着色

html - 我怎样才能使表不可扩展?或 <td> 内容的垂直扩展