:not() 选择器用于一些特殊的功能的呈现上,我举一个我使用的例子:

CSS :not()选择器怎么用

当你的鼠标hover到这些标签的时候,会想第二个标签一样改变颜色。

而当你点击第一个的时候标签“Asset Sector”,然后再把鼠标hover上去的时候就不想要这个特效了。

这个改怎么实现呐?

很简单,使用 &:not() 选择器就可以很容易解决这个问题了。

在W3CSchool 上的定义:

:not(selector)选择器匹配非指定元素/选择器的每个元素。

看我做什么操作来达到上面的效果。

原始的代码:

.pr-pos-box_tab {
  display: inline-block;
  margin-right: 5px;
  padding: 10px 12px 8px;
  color: @pr-dark-grey-2;
  font-size: 13px;
  font-weight: bold;
  background-color: @pr-middle-grey;  
  cursor: pointer;
  &:last-child{
    margin-right: 0;
  }
  &:hover{
    background-color: @pr-light-grey-7;
  }
}

改变后的代码:

.pr-pos-box_tab {
  display: inline-block;
  margin-right: 5px;
  padding: 10px 12px 8px;
  color: @pr-dark-grey-2;
  font-size: 13px;
  font-weight: bold;
  background-color: @pr-middle-grey;  
  cursor: pointer;
  &:last-child{
    margin-right: 0;
  }
}
 
 
.pr-pos-box_tab:not(.pr-pos-box_tab--selected) {
  &:hover{
    background-color: @pr-light-grey-7;
  }
}

看出不同了么?

对~用了not(.pr-pos-box_tab–selected)来使hover的时候不作用到pr-pos-box_tab–selected标签上

改变后的效果图:

css :not()选择器怎么用

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。