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.

Die CSSStyleRule-Schnittstelle repräsentiert eine einzelne CSS-Stilregel.

CSSRule CSSGroupingRule CSSStyleRule

Instanz-Eigenschaften

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 Eigenschafts-Wert-Paare der Regel bietet.

Instanz-Methoden

Erbt Methoden von seinen Vorfahren CSSGroupingRule und CSSRule.

Beispiele

Das CSS enthält eine Stilregel. Dies 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

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
CSSStyleRule
cssRules
deleteRule
insertRule
selectorText
style
styleMap

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.