Selecting Elements by ID or Class

If you’ve labeled elements with an id or class (see page 63), you can use that criteria in a selector to apply formatting to only those elements that are so labeled.

Figure 9.9. The division with an id of gaudi encloses almost the entire page (everything but the initial h1).

To select elements to format based on their id:

1.
Type # (a hash or pound sign).
2.
With no intervening space, immediately type id, where id uniquely identifies the element to which you’d like to apply the styles.
Figure 9.10. This selector will choose the div element with an id equal to “gaudi”.

To select elements to format based ...

Get HTML, XHTML, & CSS, Sixth Edition: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.