Selecting Elements by Name

Perhaps the most common criteria for choosing which elements to format is the element's name or type. For example, you might want to make all of the H1 elements big and bold and format all of the p elements with a sans-serif font.

Figure 9.6. Our (X)HTML code has two h2 elements.

To select elements to format based on their type:

Type selector, where selector is the name of the desired type of element, without any attributes (Figure 9.7).

Figure 9.7. This selector will choose all of the H2 elements in the document.


  • Unless you specify otherwise (using the techniques in the rest of this chapter) all the elements of the specified type will be formatted, no matter where they appear in your document.

  • Not all selectors need to specify an element's name. If you want to apply formatting to an entire class of elements, regardless of which type of elements have been identified with that class, you'd want to leave the name out of the selector.

  • The wild card, * (asterisk), matches any element name in your code.

  • You can choose a group of element names for a selector by using the comma to separate them. For more details, consult Specifying Groups of Elements on page 148.

    Figure 9.8. All the H2 elements are colored red.

  • Name or type selectors are well supported by current browsers.

HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: