CSSRule

Интерфейс CSSRule представляет собой одно правило CSS. Есть несколько типов правил, перечисленных в разделе Type constants ниже.

Интерфейс CSSRule определяет общие свойства для всех правил, в то время как свойства характерные только для определённых типов правил указаны в более специализированных интерфейсах для соответствующих типов этих правил.

Ссылки на CSSRule вы можете получить на странице CSSStyleSheet список cssRules.

Общие свойства для всех экземпляров CSSRule

CSSRule.cssText

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 Только для чтения

Returns the containing rule, otherwise null. E.g. if this rule is a style rule inside an @media block, the parent rule would be that CSSMediaRule.

CSSRule.parentStyleSheet Только для чтения

Returns the CSSStyleSheet object for the style sheet that contains this rule

CSSRule.type Только для чтения

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 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 The most common kind of rule: selector { prop1: val1; prop2: val2; }
CSSRule.IMPORT_RULE 3 CSSImportRule An @import rule. (Until the documentation is completed, see the interface definition in the Mozilla source code: nsIDOMCSSImportRule.)
CSSRule.MEDIA_RULE 4 CSSMediaRule
CSSRule.FONT_FACE_RULE 5 CSSFontFaceRule
CSSRule.PAGE_RULE 6 CSSPageRule
CSSRule.KEYFRAMES_RULE 7 CSSKeyframesRule Экспериментальная возможность
CSSRule.KEYFRAME_RULE 8 CSSKeyframeRule Экспериментальная возможность
Reserved for future use 9 Should be used to define color profiles in the future
CSSRule.NAMESPACE_RULE 10 CSSNamespaceRule Экспериментальная возможность
CSSRule.COUNTER_STYLE_RULE 11 CSSCounterStyleRule Экспериментальная возможность
CSSRule.SUPPORTS_RULE 12 CSSSupportsRule
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
CSS Object Model (CSSOM)
# the-cssrule-interface

Совместимость с браузерами

BCD tables only load in the browser

Смотрите также