XML technologies / CSS / Advanced websites with CSS / Behind the scenes / Selectors and the structure of CSS rules / Selector for direct parent and child elements

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

A selector for direct parent and child elements (English: parent-child selector) defines rules for HTML elements that must immediately follow another document in the inheritance chain. It is therefore a special case of the descendant selector.

A direct parent-child selector is indicated in a rule by the “>” character. Consider the following CSS rule:

body > p {
  font-weight: bold;
}

In the following example, the rule applies only to para2 because para1 and para3 are not direct descendants of the body element.

<body>
  <div class="seitenleiste">
    <p id="para1">Das ist die Seitenleiste.</p>  
  </div>
  <p id="para2">Willkommen auf der Webseite! Hier die Liste:</p>
  <ul>
    <li>
      <p id="para3">Das ist der erste und letzte Abschnitt der Liste.</p>   
    </li>
  </ul>
</body>

At the time of publication, Internet Explorer for Windows, up to and including version 6, is the most important current browser that does not support direct parent-child selectors. Use this selector only when a page is deliberately not intended to be displayed in Internet Explorer for Windows.

  

 

 

 

back to top