简体   繁体   English

:not()不会忽略带有链接的列表项中的类

[英]:not() is not ignoring class in list-items with links

I'm trying to use :not() to ignore the .current class in the first list item. 我正在尝试使用:not()来忽略第一个列表项中的.current类。

HTML: HTML:

<ul>
    <li class="current"><a href="#">Home</a></li>
    <li><a href="#">Page 2</a</li>
    <li><a href="#">Page 3</a></li>
</ul>

CSS: CSS:

ul li a:not(.current){color:red}

I can't get the :not() to ignore the .current class. 我不能得到:not()来忽略.current类。

I have also tried: 我也尝试过:

 ul li a:not(.current a){color:red}

Fiddle 小提琴

the :not applies to element in use, so apply to li which is using current in this case :not适用于使用中的元素,因此适用于在这种情况下使用current li

plus, not sure if was a typo, but in your second li , the a was missing a < in closing tag 再加上,不知道是否是一个错字,但在你的第二个li ,在a缺少一个<在关闭标签

 ul li:not(.current) a { color:red } 
 <ul> <li class="current"><a href="#">Home</a></li> <li><a href="#">Page 2</a></li> <li><a href="#">Page 3</a></li> </ul> 

Your class is on the li element in your html so: 您的课程位于html中的li元素上,因此:

ul li:not(.current) a { color: red; }

should work. 应该管用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM