inheritance

  • Revision slug: CSS/inheritance
  • Revision title: inheritance
  • Revision id: 68821
  • Created:
  • Creator: Mgjbot
  • Is current revision? No
  • Comment robot Adding: [[es:CSS:inheritance]] <<langbot>>

Revision Content

{{template.CSSRef()}}

Summary

The summary of every CSS property definition says whether that property is inherited by default ("Inherited: Yes") or not inherited by default ("Inherited: no"). This controls what happens when no value is specified for a property on an element.

Inherited properties

When no value for an inherited property has been specified on an element, the element gets the computed value of that property on its parent element. Only the root element of the document gets the initial value given in the property's summary.

A typical example of an inherited property is the {{template.Cssxref("color")}} property. Given the style rules:

 p { color: green }

and the markup

 <p>This paragraph has <em>emphasized text</em> in it.</p>

the words "emphasized text" will appear green, since the em element has inherited the value of the {{template.Cssxref("color")}} property from the p element. It does not get the initial value of the property (which is the color that is used for the root element when the page specifies no color).

Non-inherited properties

When no value for an non-inherited property (sometimes called a reset property in Mozilla code) has been specified on an element, the element gets the initial value of that property (as specified in the property's summary).

A typical example of a non-inherited property is the {{template.Cssxref("border")}} property. Given the style rules:

 p { border: medium solid }

and the markup

 <p>This paragraph has <em>emphasized text</em> in it.</p>

the words "emphasized text" will not have a border (since the initial value of {{template.Cssxref("border-style")}} is none).

Notes

The {{template.Cssxref("inherit")}} keyword allows authors to explicitly specify inheritance. It works on both inherited and non-inherited properties.

See Also

{{template.Cssxref("inherit")}}, initial value


{{ wiki.languages( { "es": "es/CSS/inheritance", "fr": "fr/CSS/H\u00e9ritage", "pl": "pl/CSS/Dziedziczenie" } ) }}

Revision Source

<p>
{{template.CSSRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p>The summary of every <a href="en/CSS_Reference">CSS property definition</a> says whether that property is inherited by default ("Inherited: Yes") or not inherited by default ("Inherited: no").  This controls what happens when no value is specified for a property on an element.
</p>
<h3 name="Inherited_properties"> Inherited properties </h3>
<p>When no value for an <b>inherited property</b> has been specified on an element, the element gets the <a href="en/CSS/computed_value">computed value</a> of that property on its parent element.  Only the root element of the document gets the <a href="en/CSS/initial_value">initial value</a> given in the property's summary.
</p><p>A typical example of an inherited property is the {{template.Cssxref("color")}} property.  Given the style rules:
</p>
<pre class="eval"> p { color: green }
</pre>
<p>and the markup
</p>
<pre class="eval"> &lt;p&gt;This paragraph has &lt;em&gt;emphasized text&lt;/em&gt; in it.&lt;/p&gt;
</pre>
<p>the words "emphasized text" will appear green, since the <code>em</code> element has inherited the value of the {{template.Cssxref("color")}} property from the <code>p</code> element.  It does <i>not</i> get the initial value of the property (which is the color that is used for the root element when the page specifies no color).
</p>
<h3 name="Non-inherited_properties"> Non-inherited properties </h3>
<p>When no value for an <b>non-inherited property</b> (sometimes called a <b>reset property</b> in Mozilla code) has been specified on an element, the element gets the <a href="en/CSS/initial_value">initial value</a> of that property (as specified in the property's summary).
</p><p>A typical example of a non-inherited property is the {{template.Cssxref("border")}} property.  Given the style rules:
</p>
<pre class="eval"> p { border: medium solid }
</pre>
<p>and the markup
</p>
<pre class="eval"> &lt;p&gt;This paragraph has &lt;em&gt;emphasized text&lt;/em&gt; in it.&lt;/p&gt;
</pre>
<p>the words "emphasized text" will not have a border (since the initial value of {{template.Cssxref("border-style")}} is <code>none</code>).
</p>
<h3 name="Notes"> Notes </h3>
<p>The {{template.Cssxref("inherit")}} keyword allows authors to explicitly specify inheritance.  It works on both inherited and non-inherited properties.
</p>
<h3 name="See_Also"> See Also </h3>
<p>{{template.Cssxref("inherit")}}, <a href="en/CSS/initial_value">initial value</a>
</p><p><br>
</p>
<div class="noinclude">
</div>
{{ wiki.languages( { "es": "es/CSS/inheritance", "fr": "fr/CSS/H\u00e9ritage", "pl": "pl/CSS/Dziedziczenie" } ) }}
Revert to this revision