css中 :not() 选择器的用法

216 阅读1分钟

如果希望某个样式不作用到选择器上,可以使用:not(选择器)
如:

<input type="text" value="1" />
<input type="text" value="2" />
<input type="text" class="no-red" value="3"/>
input[type="text"] {
    display: block;
    width: 300px;
    height: 30px;
    margin-bottom: 20px;
    padding-left: 10px;
    color: red;
}

这样写效果如下:
在这里插入图片描述
如果希望input[type=“text”]的样式不作用到第三个input上,可以这样写:

 input[type="text"]:not(.no-red) {
    display: block;
    width: 300px;
    height: 30px;
    margin-bottom: 20px;
    padding-left: 10px;
    color: red;
}

则效果如图所示:
在这里插入图片描述