类选择器
概述
在一个HTML文档中,CSS类选择器会根据元素的类属性中的内容匹配元素。类属性被定义为一个以空格分隔的列表项,在这组类名中,必须有一项与类选择器中的类名完全匹配,此条样式声明才会生效。
语法
示例
span.classy {
background-color: DodgerBlue;
}
上面的CSS作用于下面的HTML代码:
<span class="classy">Here's a span with some text.</span>
<span>Here's another.</span>
则会产生这样的效果:
Here's a span with some text.
Here's another.
规范
Specification | Status | Comment |
---|---|---|
CSS Selectors Level 3 | Recommendation | |
CSS 2.1 | Recommendation | |
CSS 1 | Recommendation |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? | ? |