“ not”伪类将被忽略

时间:2019-08-10 22:54:58

标签: html css pseudo-class

我试图了解为什么:not(...)不能按预期工作。参见示例:

.wrapper {
    background: #eee;
    padding: 0.1em 1em;
}

:not(.wrapper) a[href^='#'] {
    font-style: italic;
}
<p><a href="https://google.com/">Link to Google. Nothing special about it</a></p>
<p><a href="#foo">Link to some section in this document. It should be italic</a></p>
<p><a href="#bar">Link to some another section in this document. It should be italic</a></p>

<p>Special wrapper. Anchor-links inside it should NOT be italic. But they are:</p>

<div class="wrapper">
    <p><a href="#aaa">This link should NOT be italic</a></p>
    <p><a href="#bbb">This link should NOT be italic</a></p>
</div>

似乎:not(.wrapper)部分被忽略了,即

:not(.wrapper) a[href^='#'] {
    font-style: italic;
}

读为

a[href^='#'] {
    font-style: italic;
}

是否可以解决或解决该问题?

0 个答案:

没有答案