XML technologies / CSS / CSS Cookbook / General information / Different selectors for assigning styles / Descendant selectors (contextual selectors)

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Descendant selectors come next in the sequence and can override the definitions of type and class selectors. They typically consist of two elements, the second of which must be a “descendant” of the first:

li a {
 text-decoration: none;
}

To see the result, extend our example with HTML code containing an a element inside a li element, as shown in the next figure:

<ul id="navigation">
  <li class="warning"><a href="http://csscookbook.com">Äpfel</a></li>
  <li><a href="http://csscookbook.com">Bananen</a></li>
  <li><a href="http://csscookbook.com">Kirschen</a></li>
</ul>

Links within the list are selected by the descendant selector

Figure: Links within the list are selected by the descendant selector.

  

 

 

 

back to top