【发布时间】:2019-01-11 05:24:23
【问题描述】:
基本上我希望所有“a”元素都是红色的,除非它们是具有“data-foo”属性属性的元素的后代子元素。
这个html:
<div data-foo="whatever">
<div>
... more descendants
<a href="#">I should be default color</a>
</div>
</div>
<a href="#">I should be red</a>
使用这个 CSS:
:not([data-foo]) a {
color: red;
}
在这个例子中仍然选择了两个“a”元素。我还尝试了以下方法:
div:not([data-foo]) a
*:not([data-foo]) a
div:not([data-foo]) a
*:not(div[data-foo]) a
但是我要么什么都没有被选中,要么全部被选中。这是一个可能的选择吗?
【问题讨论】:
标签: css css-selectors