全局属性class,是一个以空格分隔的class属性列表。可允许CSS和Javascript对Class属性进行选择,通过class选择器或者类似DOM方法的方程来选取文档中某一类特定的元素。
document.getElementsByClassName.
尽管对class 的命名没有要求,但 web 开发者最好使用可以表达元素使用目的的名字,而不是描述元素(的样式)的名字(即使一个元素是斜体,但是class的命名也不应该是italics)。语义化命名即使在页面表现发生改变时仍能保持逻辑。
详细说明
| 具体条目 | 标准 | 备注 |
|---|---|---|
| WHATWG HTML Living Standard class |
Living Standard | No change from latest snapshot, HTML5.1 |
| HTML5.1 class |
Recommendation | Snapshot of WHATWG HTML Living Standard, no change from HTML5 |
| HTML5 class |
Recommendation | Snapshot of WHATWG HTML Living Standard. From HTML 4.01 Specification, class is now a true global attribute. |
| HTML 4.01 Specification class |
Recommendation | Supported on all elements but <base>, <basefont>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>. |
浏览器兼容
| 特性 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| 基础支持 | (Yes) | (Yes) [1] | (Yes) | (Yes) | (Yes) |
| 特性 | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| 基础支持 | (Yes) | (Yes) | (Yes) [1] | (Yes) | (Yes) | (Yes) |
[1] 在Firefox 32及往后的版本中,class才成为真正的全局属性。
另见
- 所有全局属性。