XML technologies / CSS / CSS Cookbook / General information / Different selectors for assigning styles / ID selectors

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

ID selectors are very similar to class selectors, except that the specification allows them to occur only once in the HTML code. A particular element (often div) is given the attribute id that the selector then targets. To create an ID selector, place a hash sign (#) directly before its name:

#navigation {
  border: 1px solid black;
  padding: 40px;
}

Then give the desired HTML element an id attribute and assign it the value navigation (see 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>

The unordered list now has its own styles

Figure: The unordered list now has its own styles.

  

 

 

 

back to top