Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想为code不在a标签内的元素设置样式。
code
a
实现这一目标的最佳方法是什么?
code:not(a code)似乎根本不起作用,至少在 Chrome 上,即使它看起来应该
code:not(a code)
我也不能让它从控制台工作。
还有其他我可以使用的纯 CSS 方法吗?
:not不支持组合选择器。
:not
如果我们谈论它的直接父母:
:not(a) > code
否则没有办法在 CSS 中做到这一点。您必须覆盖它:
code { /* some styles */ } a code { /* override previous styles */ }
实际上,您应该可以使用您的代码,或者您可以使用通配符来选择所有不被选择的元素
code:not(a *) { font-weight: bold; }
密码笔