CSS :not() 伪类

定义和用法

CSS :not() 伪类用于匹配任何不是指定元素/选择器的元素。

实例

例子 1

为所有不是 <p> 元素的元素设置文本颜色:

:not(p) {
  color: red;
}

亲自试一试

例子 2

更多使用 :not() 的示例:

.special {
  border: 2px solid maroon;
}

p:not(.special) {
  color: green;
}

body :not(p) {
  text-decoration: underline;
}

body :not(div):not(.special) {
  font-weight: bold;
}

亲自试一试

CSS 语法

:not(selector) {
  css declarations;
}

技术细节

版本: CSS3

浏览器支持

表格中的数字指定了完全支持该伪类的首个浏览器版本。

Chrome Edge Firefox Safari Opera
4.0 9.0 3.5 3.2 9.6