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.

CSSStyleRule は、単一の CSS スタイルルールを表します。

CSSRule CSSGroupingRule CSSStyleRule

インスタンスプロパティ

祖先である CSSRule からプロパティを継承しています。

CSSStyleRule.selectorText

このルールのセレクターのテキスト表現を返します。例: "h1,h2"

CSSStyleRule.style 読取専用

このルールの CSSStyleDeclaration オブジェクトを返します。

CSSStyleRule.styleMap 読取専用

StylePropertyMap オブジェクトを返し、これによってこのルールのプロパティと値の組へアクセスできます。

インスタンスメソッド

固有のメソッドはありません。祖先である CSSRule からメソッドを継承しています。

この CSS は 1 つのスタイルルールを含んでいます。これは最初の CSSRule となり、 document.styleSheets[0].cssRules で返されます。 従って、 myRules[0]h1 を定義するルールを表す CSSStyleRule オブジェクトを返します。

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

仕様書

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

ブラウザーの互換性

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.