Vue进阶(幺柒玖):css中 :not() 伪类选择器用法

举报
SHQ5785 发表于 2021/03/02 14:12:53 2021/03/02
【摘要】 单条件筛选单个的not写法:/*选中非段落元素*/:not(p){ }在前端项目开发过程中,如果希望某个样式不作用到选择器上,可以使用:not(选择器),如:<input type="text" value="1" /><input type="text" value="2" /><input type="text" class="no-red" value="3"/>input[type...

单条件筛选

单个的not写法:

/*选中非段落元素*/
:not(p)
{
 
}

在前端项目开发过程中,如果希望某个样式不作用到选择器上,可以使用: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;
}

则效果如图所示:

多条件筛选

多个not的写法

/*选中div里面非首个、非最后一个的中间p元素*/

div p:not(:first-child):not(:last-child){
}

:not 伪类选择器可以通过多条件筛选不符合表达式的元素。

table tbody tr:not(:first-child):not(:last-child) td
{
     text-align: right;
}

以上代码可以选择table表格中tbody部分非首个、非最后一个的tr,并设置其子元素td文本样式居右。

拓展阅读

【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。