From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/html/global_attributes/class/index.html | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 files/zh-cn/web/html/global_attributes/class/index.html (limited to 'files/zh-cn/web/html/global_attributes/class') diff --git a/files/zh-cn/web/html/global_attributes/class/index.html b/files/zh-cn/web/html/global_attributes/class/index.html new file mode 100644 index 0000000000..61e6611ca5 --- /dev/null +++ b/files/zh-cn/web/html/global_attributes/class/index.html @@ -0,0 +1,59 @@ +--- +title: class +slug: Web/HTML/Global_attributes/class +tags: + - Global attributes + - HTML +translation_of: Web/HTML/Global_attributes/class +--- +
{{HTMLSidebar("Global_attributes")}}
+ +

全局属性 class 的值是一个以空格分隔的元素的类名(classes )列表,它允许 CSS 和 Javascript 通过类选择器 (class selectors) 或DOM方法( {{domxref("document.getElementsByClassName")}})来选择和访问特定的元素。

+ +
{{EmbedInteractiveExample("pages/tabbed/attribute-class.html","tabbed-standard")}}
+ + + +

尽管对class 的命名没有要求,但 web 开发者最好使用可以表达元素语义目的的名称,而不是描述元素展现的名称(即使一个元素是斜体,但是 class 的命名也不应该是 italics)。语义化命名即使在页面展现发生改变时仍能合乎逻辑。

+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
具体条目标准备注
{{SpecName('HTML WHATWG', "elements.html#classes", "class")}}{{Spec2('HTML WHATWG')}}No change from latest snapshot, {{SpecName('HTML5.1')}}
{{SpecName('HTML5.1', "elements.html#classes", "class")}}{{Spec2('HTML5.1')}}Snapshot of {{SpecName('HTML WHATWG')}}, no change from {{SpecName('HTML5 W3C')}}
{{SpecName('HTML5 W3C', "elements.html#classes", "class")}}{{Spec2('HTML5 W3C')}}Snapshot of  {{SpecName('HTML WHATWG')}}. From {{SpecName('HTML4.01')}}, class is now a true global attribute.
{{SpecName('HTML4.01', "struct/global.html#h-7.5.2", "class")}}{{Spec2('HTML4.01')}}Supported on all elements but {{HTMLElement("base")}}, {{HTMLElement("basefont")}}, {{HTMLElement("head")}}, {{HTMLElement("html")}}, {{HTMLElement("meta")}}, {{HTMLElement("param")}}, {{HTMLElement("script")}}, {{HTMLElement("style")}}, and {{HTMLElement("title")}}.
+ +

浏览器兼容性

+ +

{{Compat("html.global_attributes.class")}}

+ +

另见

+ + -- cgit v1.2.3-54-g00ecf