--- title: HTMLStyleElement slug: Web/API/HTMLStyleElement tags: - API - HTML DOM - HTMLStyleElement - Reference translation_of: Web/API/HTMLStyleElement ---
{{APIRef("HTML DOM")}}

HTMLStyleElement 接口表示 {{HTMLElement("style")}} 元素。它从 {{domxref("HTMLElement")}} 和 {{domxref("LinkStyle")}} 中继承属性和方法。

这个接口不允许修改包含其中的CSS(大多数情况下)。如果需要修改CSS,前往关于使用动态样式的信息查看在DOM中用于修改特定CSS属性的对象。

{{InheritanceDiagram(600, 120)}}

属性

Inherits properties from its parent, {{domxref("HTMLElement")}}, and implements {{domxref("LinkStyle")}}.

{{domxref("HTMLStyleElement.media")}}
Is a {{domxref("DOMString")}} representing the intended destination medium for style information.
{{domxref("HTMLStyleElement.type")}}
Is a {{domxref("DOMString")}} representing the type of style being applied by this statement.
{{domxref("HTMLStyleElement.disabled")}}
Is a {{domxref("Boolean")}} value representing whether or not the stylesheet is disabled (true) or not (false).
{{domxref("LinkStyle.sheet")}} {{readonlyInline}}
Returns the {{domxref("StyleSheet")}} object associated with the given element, or null if there is none
{{domxref("HTMLStyleElement.scoped")}} {{non-standard_inline}} {{obsolete_inline}}
Is a {{domxref("Boolean")}} value indicating if the element applies to the whole document (false) or only to the parent's sub-tree (true).

方法

No specific method; inherits properties from its parent, {{domxref("HTMLElement")}}, and {{domxref("LinkStyle")}}.

规范

规范 状态 注释
{{SpecName('HTML WHATWG', "#htmlstyleelement", "HTMLStyleElement")}} {{Spec2('HTML WHATWG')}}
{{SpecName('HTML5.1', "document-metadata.html#the-style-element", "HTMLStyleElement")}} {{Spec2('HTML5.1')}}
{{SpecName('HTML5 W3C', "document-metadata.html#the-style-element", "HTMLStyleElement")}} {{Spec2('HTML5 W3C')}} The following property has been added: scoped.
{{SpecName('DOM2 HTML', 'html.html#ID-16428977', 'HTMLStyleElement')}} {{Spec2('DOM2 HTML')}} Added a second inheritence, the {{domxref("LinkStyle")}} interface.
{{SpecName('DOM1', 'level-one-html.html#ID-16428977', 'HTMLStyleElement')}} {{Spec2('DOM1')}} Initial definition

浏览器兼容性

{{Compat("api.HTMLStyleElement")}}

参见