Combining Selector Types


So far, three kinds of selectors have been described in this chapter: Type selectors, ID selectors, and class selectors. Often, different selector types are combined to form more complex selectors. By combining selectors, you can more accurately target elements that you want to give a certain presentation. For example, by combining a type selector and a class selector, an element must fulfill both requirements: It must be of the right type and the right class in order to be influenced by the style rule. Figure 4.7 shows one example.

Figure 4.7. A combined type and class selector.


In English, this selector reads, "P elements with class name POLONIUS." That is, an element must be of the right type (P), and it must also be of the right class (POLONIUS). Compare the previous example with this selector:

 .POLONIUS { font-weight: bold } 

The latter example omits the element type and starts off with the flag character. By doing so, it selects all elements with the right class, no matter what type the element is.

We see more examples of how to combine different kinds of selectors later in this chapter.



Cascading Style Sheets(c) Designing for the Web
Cascading Style Sheets: Designing for the Web (3rd Edition)
ISBN: 0321193121
EAN: 2147483647
Year: 2003
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net