CSSRule

  • Revision slug: DOM/cssRule
  • Revision title: CSSRule
  • Revision id: 85919
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment update formatting and layout; 14 words added, 75 words removed

Revision Content

{{ DomRef() }}

An object implementing the CSSRule DOM interface represents a single CSS rule. References to a CSSRule-implementing object may be obtained by looking at a CSS style sheet's cssRules list.

There are several kinds of rules. 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.

CSSRule

CSSRule rule 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:

Type Rule-specific interface
CSSRule.STYLE_RULE {{ domxref("CSSStyleRule") }}
CSSRule.MEDIA_RULE {{domxref("CSSMediaRule")}}
CSSRule.FONT_FACE_RULE {{domxref("CSSFontFaceRule")}}
CSSRule.PAGE_RULE {{domxref("CSSPageRule")}}
CSSRule.IMPORT_RULE {{domxref("CSSImportRule")}}
CSSRule.CHARSET_RULE {{domxref("CSSCharsetRule")}}
CSSRule.UNKNOWN_RULE {{domxref("CSSUnknownRule")}}

Properties of all CSSRule instances

cssText
Returns the textual representation of the rule, e.g. "h1,h2 { font-size: 16pt }"
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.
parentStyleSheet
Returns the CSSStyleSheet object for the style sheet that contains this rule
type
An integer corresponding to the CSSRule constant for this rule type

Specification

See also

{{ languages( { "pl": "pl/DOM/cssRule" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<p>An object implementing the <code>CSSRule</code> DOM interface represents a single CSS rule. References to a <code>CSSRule</code>-implementing object may be obtained by looking at a <a href="/en/DOM/CSSStyleSheet" title="en/DOM/stylesheet">CSS style sheet's</a> <code><a href="/en/DOM/CSSStyleSheet" title="en/DOM/CSSStyleSheet/cssRules">cssRules</a></code> list.</p>
<p>There are several kinds of rules. The <code>CSSRule</code> 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.</p>
<h2 name="CSSRule">CSSRule</h2>
<h3>CSSRule rule type constants</h3>
<p>The <code>CSSRule</code> interface specifies integer constants that can be used in conjunction with a <code>CSSRule</code>'s <a href="/en/DOM/cssRule/type" title="en/DOM/CSSRule/type"><code>type</code></a> property to discern the rule type (and therefore, which specialized interface it implements). The relationships between these constants and the interfaces are:</p>
<table class="standard-table"> <tbody> <tr> <th>Type</th> <th>Rule-specific interface</th> </tr> <tr> <td><code>CSSRule.STYLE_RULE</code></td> <td><code>{{ domxref("CSSStyleRule") }}</code></td> </tr> <tr> <td><code>CSSRule.MEDIA_RULE</code></td> <td><code>{{</code><code>domxref</code><code>("CSSMediaRule")}}</code></td> </tr> <tr> <td><code>CSSRule.FONT_FACE_RULE</code></td> <td><code>{{</code><code>domxref</code><code>("CSSFontFaceRule")}}</code></td> </tr> <tr> <td><code>CSSRule.PAGE_RULE</code></td> <td><code>{{</code><code>domxref</code><code>("CSSPageRule")}}</code></td> </tr> <tr> <td><code>CSSRule.IMPORT_RULE</code></td> <td><code>{{</code><code>domxref</code><code>("CSSImportRule")}}</code></td> </tr> <tr> <td><code>CSSRule.CHARSET_RULE</code></td> <td><code>{{</code><code>domxref</code><code>("CSSCharsetRule")}}</code></td> </tr> <tr> <td><code>CSSRule.UNKNOWN_RULE</code></td> <td><code>{{</code><code>domxref</code><code>("CSSUnknownRule")}}</code></td> </tr> </tbody>
</table>
<h3>Properties of all CSSRule instances</h3>
<dl> <dt id="cssText"><code><a href="/en/DOM/CSSRule/cssText" title="en/DOM/cssRule.cssText">cssText</a></code></dt> <dd>Returns the textual representation of the rule, e.g. <code>"h1,h2 { font-size: 16pt }"</code></dd> <dt id="parentRule"><code>parentRule</code> </dt> <dd>Returns the containing rule, otherwise <code>null</code>. E.g. if this rule is a style rule inside an <code><a href="/en/CSS/@media" title="en/CSS/@media">@media</a></code> block, the parent rule would be that <code><a href="/en/DOM/CSSMediaRule" title="en/DOM/CSSMediaRule">CSSMediaRule</a></code>.</dd> <dt id="parentStyleSheet"><code><a href="/en/DOM/CSSRule/parentStyleSheet" title="en/DOM/cssRule.parentStyleSheet">parentStyleSheet</a></code></dt> <dd>Returns the <code><a href="/en/DOM/CSSStyleSheet" title="en/DOM/CSSStyleSheet">CSSStyleSheet</a></code> object for the style sheet that contains this rule</dd> <dt id="type"><code>type</code></dt> <dd>An integer corresponding to the <a href="/en/DOM/cssRule#CSSRule_rule_type_constants" title="en/DOM/CSSRule#CSSRule_rule_type_constants"><code>CSSRule</code> constant</a> for this rule type</dd>
</dl>
<h2 name="Specification">Specification</h2>
<ul> <li><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRule">DOM Level 2 CSS: CSSRule</a></li> <li><a class=" external" href="http://dev.w3.org/csswg/cssom/#css-rules" title="http://dev.w3.org/csswg/cssom/#css-rules">CSS Object Model: CSS Rules</a></li>
</ul>
<h2>See also</h2>
<ul> <li><a href="/en/DOM/Using_dynamic_styling_information" title="en/DOM/Using_dynamic_styling_information">Using dynamic styling information</a></li>
</ul>
<p>{{ languages( { "pl": "pl/DOM/cssRule" } ) }}</p>
Revert to this revision