137
CHAPTER
Advanced CSS 5
In Chapter 2, IDs were used as targets for links.
Is this a different ID?
No. IDs can be used for several purposes, including
targeting links and applying styles. They can also
be used for JavaScript. A single element’s ID can
be used for any or all of these purposes on a
single page.
What is the difference between an ID and a class?
The main difference between IDs and classes is that
an ID must be unique on a page, whereas a class
can be used repeatedly. IDs are also more specific
than classes, so if an element has both an ID and a
class applied with conflicting styles, the ID’s styles
take precedence over those of the class.
● When you view the page in
the browser, the tag to which
you added the ID attribute
has the style applied.
3 Within the style sheet, type
a # and the ID you used in
Step 2.
4 Press.
5 Type {.
6 Type one or more style rules.
7 Press.
8 Type }.
6
5
8
3
TIPS