HTML and CSS Reference
In-Depth Information
The keyword inherit makes the value of a property on an element the same as the value
of that property on its parent element. In other words, it forces inheritance to occur
even in situations where it would not normally operate. In many cases, you don't need
to specify inheritance, since many properties inherit naturally. Nevertheless, inherit
can still be very useful.
For example, consider the following styles and markup:
#toolbar {background: blue; color: white;}
<div id="toolbar">
<a href="one.html">One</a> | <a href="two.html">Two</a> |
<a href="three.html">Three</a>
The div itself will have a blue background and a white foreground, but the links will
be styled according to the browser's preference settings. They'll most likely end up as
blue text on a blue background, with white vertical bars between them.
You could write a rule that explicitly sets the links in the “toolbar” to be white, but you
can make things a little more robust by using inherit . You simply add the following
rule to the style sheet:
#toolbar a {color: inherit;}
This will cause the links to use the inherited value of color in place of the user agent's
default styles. Ordinarily, directly assigned styles override inherited styles, but
inherit can undo that behavior.
Similarly, you can pull a property value down from a parent even if it wouldn't happen
normally. Take border , for example, which is (rightfully) not inherited. If you want a
span to inherit the border of its parent, all you need is span {border: inherit;} . More
likely, though, you just want the border on a span to use the same border color as its
parent. In that case span {border-color: inherit;} will do the trick.
Internet Explorer did not support inherit until IE8.
The keyword initial sets the value of a property to the defined initial value, which in
a way means it “resets” the value. For example, the default value of font-weight is
normal . Thus, declaring font-weight: initial is the same as declaring font-weight:
normal .
Search WWH ::

Custom Search