XML technologies / CSS / CSS Cookbook / General topics / Different selectors for assigning styles / Selector for adjacent siblings
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Two elements are adjacent siblings if they are directly “next to each other” in the HTML source.
To select adjacent siblings, join them with a plus sign (+), as shown here:
li + li {
font-size: 200%;
}The following figure shows the effect of adjacent sibling selector rules. They apply only to the second and third list items, because these are the only list items directly “next to each other” in the hierarchy.
Figure: The adjacent sibling selector affects only the second and third list items because they are directly “next to each other” in the hierarchy.
The diagram in the following figure shows which elements are affected by the CSS rule for adjacent siblings.
Figure: Diagram of the elements selected in the preceding figure.
Warning:
Adjacent siblings are not always supported even in modern browsers, particularly Internet Explorer 6 for Windows. However, Mozilla, Firefox, Opera 5+ and Safari handle adjacent sibling selectors correctly.
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