Adjacent Sibling Selector

From CSS Discuss

Jump to: navigation, search

CSS 2 selector

Selects an element immediately after another, and in the same level of the document tree.

For Example

EM + STRONG {color: red;} will select all STRONG elements that immediately follows an EM element. These selectors would be adjacent to each other (and have the same parent in a document tree) in terms of their containing elements. So a simple document fragment like:

<P>
   <EM>This is a child of the P element.</EM>
   <STRONG>This is an adjacent sibling to EM, and a child of P.  
   I would be selected and coloured red as per the above style.</STRONG>
</P>

The elements needn't be connected, as long as no other elements appear between them.

For instance:

<p>
   This is a sentence in a paragraph, where some 
   <em>words will be in italics</em> (emphasised, at least), and others 
   <strong>may be strong, and red</strong> which is often rendered in bold.
</p>

Support

How good is support for this selector?



Category Selector

Personal tools