CSS 如何选择具有 2 个类的元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5116288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:48:25  来源:igfitidea点击:

How to select an element with 2 classes

csscss-selectors

提问by Luca Romagnoli

Possible Duplicate:
CSS Selector that applies to elements with two classes

可能的重复:
适用于具有两个类的元素的 CSS 选择器

i have this elements

我有这个元素

<div class="a b"></div>
<div class="b"></div>
<div class="a"></div>

I want apply to element with class a and b the color #666. How can I do this with CSS?

我想应用于 a 类和 b 类的元素,颜色为 #666。我怎样才能用 CSS 做到这一点?

回答by BoltClock

You can chain class selectors without a spacebetween them:

您可以链接类选择器,它们之间没有空格

.a.b {
     color: #666;
}

Note that, if it matters to you, IE6 treats .a.bas .b, so in that browser both div.a.band div.bwill have gray text. See this answerfor a comparison between proper browsers and IE6.

需要注意的是,如果对你很重要,IE6对待.a.b.b,所以在这两种浏览器div.a.bdiv.b将灰色文本。有关正确浏览器和 IE6 之间的比较,请参阅此答案

回答by htanata

Just chain them together:

只需将它们链接在一起:

.a.b {
  color: #666;
}