CSSRule

  • Revision slug: DOM/cssRule
  • Revision title: CSSRule
  • Revision id: 85911
  • Created:
  • Creator: Sevenspade
  • Is current revision? No
  • Comment format and link; one or more formatting changes

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 stylesheet'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

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 {{ Anch("CSSStyleRule") }}
CSSRule.MEDIA_RULE {{ Anch("CSSMediaRule") }}
CSSRule.FONT_FACE_RULE {{ Anch("CSSFontFaceRule") }}
CSSRule.PAGE_RULE {{ Anch("CSSPageRule") }}
CSSRule.IMPORT_RULE {{ Anch("CSSImportRule") }}
CSSRule.CHARSET_RULE {{ Anch("CSSCharsetRule") }}
CSSRule.UNKNOWN_RULE {{ Anch("CSSUnknownRule") }}

Properties of CSSRule instances

cssText 
Returns the textual representation of the rule, e.g. "h1,h2 { font-size: 16pt }"
parentRule 
Returns the containing rule, if any (e.g. a style rule inside an @media block)
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

CSSStyleRule

selectorText 
Gets/sets the textual representation of the selector for this rule, e.g. "h1,h2".
style 
Returns the CSSStyleDeclaration object for the declaration block of the rule.

CSSMediaRule

CSSFontFaceRule

CSSPageRule

CSSImportRule

CSSCharsetRule

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/stylesheet" title="en/DOM/stylesheet">stylesheet</a>'s <code><a href="/en/DOM/stylesheet.cssRules" title="en/DOM/stylesheet.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>
<p>The <code>CSSRule</code> interface specifies integer constants that can be used in conjunction with a <code>CSSRule</code>'s <code><a href="en/DOM/cssRule/type" title="en/DOM/cssRule/type">type</a></code> property to discern the rule type (and therefore, which specialized interface it implements).  The relationships between these constants and the interfaces are</p>
<table> <tbody> <tr> <th>Type</th> <th>Rule-specific interface</th> </tr> <tr> <td><code>CSSRule.STYLE_RULE</code></td> <td><code>{{ Anch("CSSStyleRule") }}</code></td> </tr> <tr> <td><code>CSSRule.MEDIA_RULE</code></td> <td><code>{{ Anch("CSSMediaRule") }}</code></td> </tr> <tr> <td><code>CSSRule.FONT_FACE_RULE</code></td> <td><code>{{ Anch("CSSFontFaceRule") }}</code></td> </tr> <tr> <td><code>CSSRule.PAGE_RULE</code></td> <td><code>{{ Anch("CSSPageRule") }}</code></td> </tr> <tr> <td><code>CSSRule.IMPORT_RULE</code></td> <td><code>{{ Anch("CSSImportRule") }}</code></td> </tr> <tr> <td><code>CSSRule.CHARSET_RULE</code></td> <td><code>{{ Anch("CSSCharsetRule") }}</code></td> </tr> <tr> <td><code>CSSRule.UNKNOWN_RULE</code></td> <td><code>{{ Anch("CSSUnknownRule") }}</code></td> </tr> </tbody>
</table>
<h4>Properties of CSSRule instances</h4>
<dl> <dt><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. "h1,h2 { font-size: 16pt }"</dd> <dt><code><a href="/en/DOM/cssRule.parentRule" title="en/DOM/cssRule.parentRule">parentRule</a></code> </dt> <dd>Returns the containing rule, if any (e.g. a style rule inside an <code><a href="/en/CSS/@media" title="en/CSS/@media">@media</a></code> block)</dd> <dt><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><code><a href="/en/DOM/cssRule.type" title="en/DOM/cssRule.type">type</a></code> </dt> <dd>An integer corresponding to the <code>CSSRule</code> constant for this rule type</dd>
</dl><h2 name="CSSStyleRule">CSSStyleRule</h2>
<dl> <dt><code><a href="/en/DOM/CSSStyleRule/selectorText" title="en/DOM/cssRule.selectorText">selectorText</a></code> </dt> <dd>Gets/sets the textual representation of the selector for this rule, e.g. "h1,h2".</dd> <dt><code><a href="/en/DOM/CSSStyleRule/style" title="en/DOM/cssRule.style">style</a></code> </dt> <dd>Returns the <code><a href="/en/DOM/CSSStyleDeclaration" title="en/DOM/CSSStyleDeclaration">CSSStyleDeclaration</a></code> object for the <a class="external" href="http://www.w3.org/TR/1998/REC-CSS2-19980512/syndata.html#block">declaration block</a> of the rule.</dd>
</dl>
<h2 name="CSSStyleRule_2">CSSMediaRule</h2>
<h2 name="CSSFontFaceRule">CSSFontFaceRule</h2>
<h2 name="CSSPageRule">CSSPageRule</h2>
<h2 name="CSSImportRule">CSSImportRule</h2>
<h2 name="CSSCharsetRule">CSSCharsetRule</h2>
<h2 name="CSSUnknownRule">CSSUnknownRule</h2>
<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