--- title: CSSStyleDeclaration slug: Web/API/CSSStyleDeclaration translation_of: Web/API/CSSStyleDeclaration ---
{{ APIRef("CSSOM") }}
CSSStyleDeclaration
表示了一個 CSS 屬性名值對(property-value pairs)的集合。它被用於幾個 API 當中:
style
property of a cssRule
in a stylesheet, when the rule is a CSSStyleRule.CSSStyleDeclaration
is also a read-only interface to the result of window.getComputedStyle().null
for shorthand properties.var styleObj = document.styleSheets[0].cssRules[0].style; console.log(styleObj.cssText); for (var i = styleObj.length; i--;) { var nameString = styleObj[i]; styleObj.removeProperty(nameString); } console.log(styleObj.cssText);
The declaration block is that part of the style rule that appears within the braces and that actually provides the style definitions (for the selector, the part that comes before the braces).
Specification | Status | Comment |
---|---|---|
{{SpecName('CSSOM', '#the-cssstyledeclaration-interface', 'CSSStyleDeclaration')}} | {{Spec2('CSSOM')}} | |
{{SpecName('DOM2 Style', 'css.html#CSS-CSSStyleDeclaration', 'CSSPrimitiveValue')}} | {{Spec2('DOM2 Style')}} | Initial definition |