CSSRule - Web APIs 编辑

The CSSRule interface represents a single CSS rule. There are several types of rules, listed in the Type constants section below.

The CSSRule interface specifies the properties common to all rules, while properties unique to specific rule types are specified in the more specialized interfaces for those rules' respective types.

References to a CSSRule may be obtained by looking at a CSSStyleSheet's cssRules list.

Properties common to all CSSRule instances

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 Read only
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 Read only
Returns the CSSStyleSheet object for the style sheet that contains this rule
CSSRule.type Read only
One of the Type constants indicating the type of CSS rule.

Constants

Type constants

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:

TypeValueRule-specific interfaceComments and examples
CSSRule.STYLE_RULE1CSSStyleRuleThe most common kind of rule:
selector { prop1: val1; prop2: val2; }
CSSRule.IMPORT_RULE3CSSImportRuleAn @import rule. (Until the documentation is completed, see the interface definition in the Mozilla source code: nsIDOMCSSImportRule.)
CSSRule.MEDIA_RULE4CSSMediaRule
CSSRule.FONT_FACE_RULE5CSSFontFaceRule
CSSRule.PAGE_RULE6CSSPageRule
CSSRule.KEYFRAMES_RULE7CSSKeyframesRule This is an experimental API that should not be used in production code.
CSSRule.KEYFRAME_RULE8CSSKeyframeRule This is an experimental API that should not be used in production code.
Reserved for future use9Should be used to define color profiles in the future
CSSRule.NAMESPACE_RULE10CSSNamespaceRule This is an experimental API that should not be used in production code.
CSSRule.COUNTER_STYLE_RULE11CSSCounterStyleRule This is an experimental API that should not be used in production code.
CSSRule.SUPPORTS_RULE12CSSSupportsRule
CSSRule.DOCUMENT_RULE13CSSDocumentRule This is an experimental API that should not be used in production code.
CSSRule.FONT_FEATURE_VALUES_RULE14CSSFontFeatureValuesRule
CSSRule.VIEWPORT_RULE15CSSViewportRule This is an experimental API that should not be used in production code.
CSSRule.REGION_STYLE_RULE16CSSRegionStyleRule This is an experimental API that should not be used in production code.
CSSRule.UNKNOWN_RULE0CSSUnknownRule This is an obsolete API and is no longer guaranteed to work.
CSSRule.CHARSET_RULE2CSSCharsetRule This is an obsolete API and is no longer guaranteed to work.(Removed in most browsers.)

An up-to-date informal list of constants can be found on the CSSWG Wiki.

Specifications

SpecificationStatusComment
CSS Object Model (CSSOM)
The definition of 'CSSRule' in that specification.
Working DraftObsoleted values CHARSET_RULE and UNKNOWN_RULE. Added value NAMESPACE_RULE.
CSS Animations Level 1
The definition of 'CSSRule' in that specification.
Working DraftAdded values KEYFRAMES_RULE and KEYFRAME_RULE.
CSS Fonts Module Level 4
The definition of 'CSSRule' in that specification.
Working DraftAdded value FONT_FEATURE_VALUES_RULE.
CSS Counter Styles Level 3
The definition of 'CSSRule' in that specification.
Candidate RecommendationAdded value COUNTER_STYLE_RULE.
CSS Conditional Rules Module Level 3
The definition of 'CSSRule' in that specification.
Candidate RecommendationAdded value SUPPORTS_RULE. (DOCUMENT_RULE has been pushed to CSS Conditional Rules Level 4)
Document Object Model (DOM) Level 2 Style Specification
The definition of 'CSSRule' in that specification.
ObsoleteInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:57 次

字数:16185

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文