Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. CSSRule

CSSRule

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheCSSRule interface represents a single CSS rule. There are several types of rules which inherit properties fromCSSRule.

Instance properties

TheCSSRule interface specifies the properties common to all rules, while properties unique to specific rule types are specified in the more specialized interfaces for those rules' respective types.

CSSRule.cssText

Represents the textual representation of the rule, e.g.,"h1,h2 { font-size: 16pt }" or"@import 'url'". To access or modify parts of the rule (e.g., the value of "font-size" in the example) use the properties on the specialized interface for the rule's type (see above).

CSSRule.parentRuleRead only

Returns the containing rule, otherwisenull. E.g. if this rule is a style rule inside an@media block, the parent rule would be thatCSSMediaRule.

CSSRule.parentStyleSheetRead only

Returns theCSSStyleSheet object for the style sheet that contains this rule

CSSRule.typeRead onlyDeprecated

Returns one of the Type constants to determine which type of rule is represented.

Examples

References to aCSSRule may be obtained by looking at aCSSStyleSheet'scssRules list.

js
let myRules = document.styleSheets[0].cssRules; // Returns a CSSRuleListconsole.log(myRules);

Specifications

Specification
CSS Object Model (CSSOM)
# the-cssrule-interface

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp