mozilla

Revision 296728 of CSSRule

  • Revision slug: DOM/cssRule
  • Revision title: CSSRule
  • Revision id: 296728
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSOMRef() }}

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 Value Rule-specific interface
CSSRule.STYLE_RULE 1 {{ domxref("CSSStyleRule") }}
CSSRule.MEDIA_RULE 4 {{ domxref("CSSMediaRule") }}
CSSRule.FONT_FACE_RULE 5 {{ domxref("CSSFontFaceRule") }}
CSSRule.PAGE_RULE 6 {{ domxref("CSSPageRule") }}
CSSRule.IMPORT_RULE 3 {{ domxref("CSSImportRule") }}
CSSRule.CHARSET_RULE 2 {{ domxref("CSSCharsetRule") }} {{ obsolete_inline() }}
CSSRule.UNKNOWN_RULE   {{ domxref("CSSUnknownRule") }}{{ obsolete_inline() }}
CSSRule.KEYFRAMES_RULE   {{ domxref("CSSKeyframesRule") }}
CSSRule.KEYFRAME_RULE   {{ domxref("CSSKeyframeRule") }}
CSSRule.NAMESPACE_RULE 10 {{ domxref("CSSNamespaceRule") }}
CSSRule.SUPPORTS_RULE 12 {{ domxref("CSSSupportsRule") }} {{ experimental_inline() }}
CSSRule.DOCUMENT_RULE 13 {{ domxref("CSSDocumentRule") }} {{ experimental_inline() }}

The {{ domxref("CSSMozDocumentRule") }} does not have a corresponding type constant.

Specification

See also

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

Revision Source

<p>{{ CSSOMRef() }}</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 id="Properties_of_all_CSSRule_instances">Properties of all CSSRule instances</h2>
<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") }}&nbsp;indicating the type of CSS&nbsp;rule.</dd>
</dl>
<h2 id="CSSRule" name="CSSRule">Constants</h2>
<h3 id="Type_constants">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>Value</th>
      <th>Rule-specific interface</th>
    </tr>
    <tr>
      <td><code>CSSRule.STYLE_RULE</code></td>
      <td style="text-align: center;"><code>1</code></td>
      <td>{{ domxref("CSSStyleRule") }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.MEDIA_RULE</code></td>
      <td style="text-align: center;"><code>4</code></td>
      <td>{{ domxref("CSSMediaRule") }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.FONT_FACE_RULE</code></td>
      <td style="text-align: center;"><code>5</code></td>
      <td>{{ domxref("CSSFontFaceRule") }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.PAGE_RULE</code></td>
      <td style="text-align: center;"><code>6</code></td>
      <td>{{ domxref("CSSPageRule") }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.IMPORT_RULE</code></td>
      <td style="text-align: center;"><code>3</code></td>
      <td>{{ domxref("CSSImportRule") }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.CHARSET_RULE</code></td>
      <td style="text-align: center;"><code>2</code></td>
      <td>{{ domxref("CSSCharsetRule") }} {{ obsolete_inline() }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.UNKNOWN_RULE</code></td>
      <td style="text-align: center;">&nbsp;</td>
      <td>{{ domxref("CSSUnknownRule") }}{{ obsolete_inline() }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.KEYFRAMES_RULE</code></td>
      <td style="text-align: center;">&nbsp;</td>
      <td>{{ domxref("CSSKeyframesRule") }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.KEYFRAME_RULE</code></td>
      <td style="text-align: center;">&nbsp;</td>
      <td>{{ domxref("CSSKeyframeRule") }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.NAMESPACE_RULE</code></td>
      <td style="text-align: center;"><code>10</code></td>
      <td>{{ domxref("CSSNamespaceRule") }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.SUPPORTS_RULE</code></td>
      <td style="text-align: center;"><code>12</code></td>
      <td>{{ domxref("CSSSupportsRule") }} {{ experimental_inline() }}</td>
    </tr>
    <tr>
      <td><code>CSSRule.DOCUMENT_RULE</code></td>
      <td style="text-align: center;"><code>13</code></td>
      <td>{{ domxref("CSSDocumentRule") }} {{ experimental_inline() }}</td>
    </tr>
  </tbody>
</table>
<p>The {{ domxref("CSSMozDocumentRule") }} does not have a corresponding type constant.</p>
<h2 id="Specification" 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 id="See_also">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