【发布时间】:2013-11-02 01:09:17
【问题描述】:
我只想选择只有一个类且该类是“foobar”的元素。
<style>
.foobar {
/* only apply to an element if the element has a class and the only class is 'foobar'. */
background: black;
color: white;
}
</style>
<div class="foobar">i should be selected</div>
<div class="foobar ipsum">i should not be selected</div>
我知道我可以通过为 .foobar.ipsum { do one thing } 和 .foobar { something else } 添加样式来选择它,但我无法控制其他类。基本上当元素只有 foobar 类时,我知道它是我的元素并且来自其他地方。这就是 CSS 库世界发生碰撞时发生的情况。我知道这里有更深层次的问题需要解决,但这让我现在很困惑。
【问题讨论】:
标签: html css css-selectors