简体   繁体   English

CSS不是选择器

[英]CSS Not Selector

I'm trying to use a :not() CSS selector, and I've tried multiple combinations of this and nothing is working. 我正在尝试使用:not() CSS选择器,并且尝试了多种选择,但没有任何效果。

My code is here: http://jsfiddle.net/cLevkr4e/2/ 我的代码在这里: http : //jsfiddle.net/cLevkr4e/2/

I would like it to be that when I hover over an href in #steps , it doesn't highlight the rest of the containing <li> . 我希望当我将鼠标悬停在#steps的href #steps ,它不会突出显示其余的<li>

I would also like it that when I hover over an <li> in #steps , it applies the hover color change to everything, including the anchor tags. 我还希望当我在#steps鼠标悬停在<li>#steps ,它将悬停颜色更改应用于所有内容,包括锚标记。

So when hovering over .wa a it should just underline that. 因此,将.wa a悬停在.wa a ,应在其下划线。

When hovering over the <li> it should just change the color of everything including the anchors to rgb(66, 81, 95) . 将鼠标悬停在<li> ,应仅将包括锚点在内的所有内容更改为rgb(66, 81, 95)的颜色。

My CSS: 我的CSS:

 .wa a{
color: rgb(68, 118, 67);
}

.steps {
width:400px;
margin:0 auto;
text-align:left;
line-height: 200%;
}

.steps a:hover {
text-decoration: underline;
}

.steps li:not(a):hover{
cursor: pointer;
color: rgb(66, 81, 95);
}

My HTML: 我的HTML:

<div class="steps">
<ul>
<li>Apply an Email To Your Nation</li>
<li>Apply To the <span class="wa"><a href="http://www.nationstates.net/page=un">World Assembly</a></span> With That Email</li>
<li>Join the <span class="wa"><a href="http://www.nationstates.net/page=un">World Assembly</a></span></li>
</div>

Your selector ( li:not(a):hover ) says: When the user overs over a list item that is not an anchor . 您的选择器( li:not(a):hover )说: 当用户越过不是锚点的列表项时 An <li> will never be a <a> . <li>永远不会是<a>

I would like it to be that when I hover over an href in #steps, it doesn't highlight the rest of the containing <li> . 我想当我将鼠标悬停在#steps中的href上方时,它不会突出显示其余的<li>

When hovering over the <li> it should just change the color of everything including the anchors to rgb(66, 81, 95) . 将鼠标悬停在<li> ,应仅将包括锚点在内的所有内容更改为rgb(66, 81, 95)的颜色。

The problem here is that you cannot point the mouse at the link without also pointing it at the list item that the link is inside. 这里的问题是,您不能将鼠标指向链接而不将鼠标指向链接所在的列表项。

CSS 4 proposes :has() which would allow: CSS 4提出了:has() ,它可以:

li:hover {
    color: rgb(66, 81, 95)l
}

li:hover:has(a:hover) {
    color: black;
}

… but nothing currently supports that so what you are looking for is impossible in CSS at present. …但是目前还没有任何支持,因此目前您在CSS中找不到想要的东西。 You could use JavaScript to add and remove classes from the list item when the anchor is hovered though. 当锚点悬停时,您可以使用JavaScript在列表项中添加和删除类。

This li:not(a) makes no sense. li:not(a)没有道理。 Element cannot have li and `a' tags at the same time. 元素不能同时具有li和`a'标记。

What you need here is a hypothetical :has() selector but it does not exist yet . 这里需要的是一个假设的:has()选择器,但它尚不存在 Only with it it would be possible to achieve what you want: 只有有了它,才有可能实现您想要的:

li:hover { color:red; }
li:hover a { color:inherit; }
li:has(a:hover) { color:black; }

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

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