CSSRule

  • Revision slug: DOM/cssRule
  • Revision title: CSSRule
  • Revision id: 85920
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment more cleanup; 103 words added, 93 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.

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
One of the {{ anch("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:

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") }}

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>
<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"><a href="/en/DOM/cssRule/parentRule" title="en/DOM/cssRule/parentRule"><code>parentRule</code></a> </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"><a href="/en/DOM/cssRule/type" title="en/DOM/cssRule/type"><code>type</code></a></dt> <dd>One of the {{ anch("Type constants") }} indicating the type of CSS rule.</dd>
</dl>
<h2 name="CSSRule">Constants</h2>
<h3>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>{{ domxref("CSSStyleRule") }}</td> </tr> <tr> <td><code>CSSRule.MEDIA_RULE</code></td> <td>{{ domxref("CSSMediaRule") }}</td> </tr> <tr> <td><code>CSSRule.FONT_FACE_RULE</code></td> <td>{{ domxref("CSSFontFaceRule") }}</td> </tr> <tr> <td><code>CSSRule.PAGE_RULE</code></td> <td>{{ domxref("CSSPageRule") }}</td> </tr> <tr> <td><code>CSSRule.IMPORT_RULE</code></td> <td>{{ domxref("CSSImportRule") }}</td> </tr> <tr> <td><code>CSSRule.CHARSET_RULE</code></td> <td>{{ domxref("CSSCharsetRule") }}</td> </tr> <tr> <td><code>CSSRule.UNKNOWN_RULE</code></td> <td>{{ domxref("CSSUnknownRule") }}</td> </tr> </tbody>
</table>
<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></dl>
Revert to this revision