The University of Texas at Austin- What Starts Here Changes the World
Services Navigation


Inheritance

When one element is contained within another, with the exception of tables in Netscape 4, it will inherit properties from the container. The classic example is an emphasis contained within a header.

this HTML markup renders like this
<h1>Style sheets <em>rule!</em></h1>

Style sheets rule!

The emphasized text will be rendered in italics, but have the same typeface, color, background, etc, as the rest of the header. We can override this default by specifying the behavior of the EM tag when it is used within an H1 tag.

this CSS Markup renders like this
H1 EM { color: red }
style sheets rule with red rule

Here, the EM is separated from the H1 by a space rather than by a comma as in the previous example. This is called a contextual selector. It defines a rule for the EM tag when used in the context of an H1 tag. Another common application of contextual selectors is to specify the list style for nested lists. In this next example, an OL tag by itself produces a list with a decimal numbering scheme. When an OL tag is used within the context of another OL tag, lowercase roman numerals are used. And when an OL tag is used within two OL tags, the different list items are denoted with lowercase alphabetic characters.

with this style rule:

OL { list-style: decimal }

OL OL { list-style: lower-roman }

OL OL OL { list-style: lower-alpha }

this HTML markup renders like this

<ol>

<li> This is an item

<ol>

<li>This is an item in a sublist
<li>And another item

</ol>

<li> And another item for the top level
<li> Still more items

<ol>

<li> More items in another sublist
<li> And more
<li> And now let's add another sublist

<ol>

<li> Now we are three lists deep
<li> We want these to be marked with lowercase letters

</ol>

</ol>

</ol>

  1. This is an item
    1. This is an item in a sublist
    2. And another item
  2. And another item for the top level
  3. Still more items
    1. More items in another sublist
    2. And more
    3. And now let's add another sublist
      1. Now we are three lists deep
      2. We want these to be marked with lowercase letters





  Updated 2006 August 14
  Comments to www@www.utexas.edu