html - :not() is not ignoring class in list-items with links

标签 html css pseudo-class

我正在尝试使用 :not() 忽略第一个列表项中的 .current 类。

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:

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

我无法让 :not() 忽略 .current 类。

我也试过:

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

Fiddle

最佳答案

:not 适用于正在使用的元素,因此适用于 li正在使用 current在这种情况下

另外,不确定是否是错字,但在你的第二个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>

关于html - :not() is not ignoring class in list-items with links,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35615221/

相关文章:

html - 如何在横幅图片后面放置一个可点击的图标?

html - 如何在两侧实现多种颜色和对 Angular 线形式的背景?

php - 使用 JSON 和 PHP5 的 Kendo Grid

html - 在导航栏 div 内对齐图像

javascript - 将最后一个可见的伪元素向左移动 12px

javascript - 知道为什么矩形不会出现在我的 Fabricjs Canvas 中吗?

javascript - SVG 文本元素的就绪事件

CSS 特定 id 伪类的属性?

html - 一个 :before psuedo element before four h1. .?