CSSRule
Интерфейс CSSRule представляет собой одно правило CSS. Есть несколько типов правил, перечисленных в разделе Type constants ниже.
Интерфейс CSSRule определяет общие свойства для всех правил, в то время как свойства характерные только для определённых типов правил указаны в более специализированных интерфейсах для соответствующих типов этих правил.
Ссылки на CSSRule вы можете получить на странице CSSStyleSheet
список cssRules.
Общие свойства для всех экземпляров CSSRule
CSSRule.cssText
(en-US)- 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. CSSRule.parentRule
(en-US) Только для чтения- Returns the containing rule, otherwise
null
. E.g. if this rule is a style rule inside an@media
block, the parent rule would be thatCSSMediaRule
(en-US). CSSRule.parentStyleSheet
(en-US) Только для чтения- Returns the
CSSStyleSheet
object for the style sheet that contains this rule CSSRule.type
(en-US) Только для чтения- One of the Type constants indicating the type of CSS rule.
Константы
Типы констант
The CSSRule
interface specifies integer constants that can be used in conjunction with a CSSRule
's type
(en-US) property to discern the rule type (and therefore, which specialized interface it implements). The relationships between these constants and the interfaces are:
Type | Value | Rule-specific interface | Comments and examples |
---|---|---|---|
CSSRule.STYLE_RULE |
1 |
CSSStyleRule (en-US) |
The most common kind of rule:selector { prop1: val1; prop2: val2; } |
CSSRule.IMPORT_RULE |
3 |
CSSImportRule (en-US) |
An @import (en-US) rule. (Until the documentation is completed, see the interface definition in the Mozilla source code: nsIDOMCSSImportRule.) |
CSSRule.MEDIA_RULE |
4 |
CSSMediaRule (en-US) |
|
CSSRule.FONT_FACE_RULE |
5 |
CSSFontFaceRule (en-US) |
|
CSSRule.PAGE_RULE |
6 |
CSSPageRule (en-US) |
|
CSSRule.KEYFRAMES_RULE |
7 |
CSSKeyframesRule (en-US) |
|
CSSRule.KEYFRAME_RULE |
8 |
CSSKeyframeRule (en-US) |
|
Reserved for future use | 9 |
Should be used to define color profiles in the future | |
CSSRule.NAMESPACE_RULE |
10 |
CSSNamespaceRule (en-US) |
|
CSSRule.COUNTER_STYLE_RULE |
11 |
CSSCounterStyleRule (en-US) |
|
CSSRule.SUPPORTS_RULE |
12 |
CSSSupportsRule (en-US) |
|
CSSRule.DOCUMENT_RULE |
13 |
CSSDocumentRule |
|
CSSRule.FONT_FEATURE_VALUES_RULE |
14 |
CSSFontFeatureValuesRule |
|
CSSRule.VIEWPORT_RULE |
15 |
CSSViewportRule |
|
CSSRule.REGION_STYLE_RULE |
16 |
CSSRegionStyleRule |
|
CSSRule.UNKNOWN_RULE |
0 |
CSSUnknownRule |
|
CSSRule.CHARSET_RULE |
2 |
CSSCharsetRule |
(Removed in most browsers.) |
An up-to-date informal list of constants can be found on the CSSWG Wiki.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) Определение 'CSSRule' в этой спецификации. |
Рабочий черновик | Obsoleted values CHARSET_RULE and UNKNOWN_RULE . Added value NAMESPACE_RULE . |
CSS Animations Level 1 Определение 'CSSRule' в этой спецификации. |
Рабочий черновик | Added values KEYFRAMES_RULE and KEYFRAME_RULE . |
CSS Fonts Module Level 3 Определение 'CSSRule' в этой спецификации. |
Рекомендация | Added value FONT_FEATURE_VALUES_RULE . |
CSS Counter Styles Level 3 Определение 'CSSRule' в этой спецификации. |
Кандидат в рекомендации | Added value COUNTER_STYLE_RULE . |
CSS Conditional Rules Module Level 3 Определение 'CSSRule' в этой спецификации. |
Кандидат в рекомендации | Added value SUPPORTS_RULE . (DOCUMENT_RULE has been pushed to CSS Conditional Rules Level 4) |
Document Object Model (DOM) Level 2 Style Specification Определение 'CSSRule' в этой спецификации. |
Устаревшая | Initial definition. |
Browser compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | (Да) | (Да) | (Да) | 9 | (Да) | (Да) |
CSSKeyframesRule |
? | ? | 20.0 [4] | ? | ? | ? |
CSSCharsetRule |
Нет [1] | ? | Нет [3] | ? | Нет | ? |
CSSUnknownRule |
Нет [2] | ? | ? | ? | ? | ? |
Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | ? | (Да) | (Да) | (Да) | (Да) | (Да) | (Да) | (Да) |
CSSKeyframesRule |
? | ? | ? | 20.0 [4] | ? | ? | ? | ? |
CSSCharsetRule |
? | Нет [1] | ? | Нет [3] | ? | Нет | ? | Нет [1] |
CSSUnknownRule |
? | Нет [2] | ? | ? | ? | ? | ? | Нет [2] |
[1] CSSCharsetRule
was removed in Chrome version 41.0.
[2] CSSUnknownRule
was removed in Chrome version 45.0.
[3] CSSCharsetRule
was removed in Gecko version 40.
[4] On Gecko, before Firefox 19, the keyframe-related constants existed only in their prefixed version: CSSRule.MOZ_KEYFRAMES_RULE
and CSSRule.MOZ_KEYFRAME_RULE.
From Firefox 20 onwards, both versions are available. The prefixed version will be removed in the future.