CSSStyleRule

Baseline Widely available *

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

* Some parts of this feature may have varying levels of support.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Die CSSStyleRule-Schnittstelle repräsentiert eine einzelne CSS-Style-Regel.

CSSRule CSSGroupingRule CSSStyleRule

Instanzeigenschaften

Erbt Eigenschaften von seinen Vorfahren CSSGroupingRule und CSSRule.

CSSStyleRule.selectorText

Gibt die textuelle Darstellung des Selektors für diese Regel zurück, z. B. "h1, h2".

CSSStyleRule.style Schreibgeschützt

Gibt das CSSStyleDeclaration-Objekt für die Regel zurück.

CSSStyleRule.styleMap Schreibgeschützt

Gibt ein StylePropertyMap-Objekt zurück, das Zugriff auf die Eigenschaft-Wert-Paare der Regel bietet.

Instanzmethoden

Erbt Methoden von seinen Vorfahren CSSGroupingRule und CSSRule.

Beispiele

Das CSS enthält eine Stilregel. Diese wird die erste CSSRule sein, die von document.styleSheets[0].cssRules zurückgegeben wird. myRules[0] gibt daher ein CSSStyleRule-Objekt zurück, das die für h1 definierte Regel darstellt.

css
h1 {
  color: pink;
}
js
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0]); // a CSSStyleRule representing the h1.

Spezifikationen

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

Browser-Kompatibilität