-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
51 lines (35 loc) · 1.31 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
title: CSSStyleRule
slug: Web/API/CSSStyleRule
page-type: web-api-interface
browser-compat: api.CSSStyleRule
---
{{ APIRef("CSSOM") }}
The **`CSSStyleRule`** interface represents a single CSS style rule.
{{InheritanceDiagram}}
## Instance properties
_Inherits properties from its ancestor {{domxref("CSSRule")}}._
- {{domxref("CSSStyleRule.selectorText")}}
- : Returns the textual representation of the selector for this rule, e.g. `"h1, h2"`.
- {{domxref("CSSStyleRule.style")}} {{ReadOnlyInline}}
- : Returns the {{domxref("CSSStyleDeclaration")}} object for the rule.
- {{domxref("CSSStyleRule.styleMap")}} {{ReadOnlyInline}}
- : Returns a {{domxref('StylePropertyMap')}} object which provides access to the rule's property-value pairs.
## Instance methods
_No specific methods; inherits methods from its ancestor {{domxref("CSSRule")}}._
## Examples
The CSS includes one style rule. This will be the first {{domxref("CSSRule")}} returned by `document.styleSheets[0].cssRules`.
`myRules[0]` therefore returns a {{domxref("CSSStyleRule")}} object representing the rule defined for `h1`.
```css
h1 {
color: pink;
}
```
```js
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0]); // a CSSStyleRule representing the h1.
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}