XML technologies / CSS / CSS Cookbook / General information / Different selectors for assigning styles / Child selectors
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
A child selector selects an element that must be a direct descendant of its parent. A child selector is represented by a closing angle bracket, often between two type selectors, as shown here:
p > strong {
text-decoration: underline;
}In this example, the element strong is underlined only when it is directly inside the p element (see the next figure):
<div>
In diesem Teil des Satzes passiert gar nichts, weil <strong>strong</strong> kein direkter Nachkomme des div-Elements ist
<p>Dieses <strong>strong-Element</strong> ist dagegen ein Kind-Element des p-Elements und erhält daher die in der CSS-Regel für diesen Fall festgelegten Stildefinitionen.</p>
</div>Figure: Effect of the child-selector rule.
The diagram in the following figure shows which elements the CSS rule affects.
Figure: The element selected by the child selector within the page structure.
The first strong element in the two figures is not underlined because it is not inside the p element. The style requires a direct parent-child relationship between the elements. This is a simple but essential difference between a descendant selector and a child selector.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln
back to top