It??™s especially
important that you make sure JavaScript-related IDs appear only
once in a page, or the JavaScript may behave unpredictably.
Don??™t Go Crazy with Classes
Generally, you should use IDs and classes sparingly; the right kind of use is putting them on the divs that contain the
main sections of your markup, and then accessing the tags within them with contextual selectors that begin with the ID
or class??™s name.
What you want to avoid is what Jeffrey Zeldman describes as ???classitis??”the measles of markup,??? where you add
a unique class or ID to just about every tag in your markup and then write a rule for each one. This is only one step
removed from loading up your markup with FONT tags and other extraneous markup. The good doctor Zeldman has
cured me and many others of this nasty af?¬‚ iction. If you are already in the habit of slapping classes on every tag, as most
of us do when we enthusiastically jump into CSS, take a look at the markup sample in Chapter 1 in light of what you just
read in this chapter. You??™ll see that you can target styles at every tag quite easily without adding any more IDs or classes.
If you use IDs to identify only the main sections of your markup??”and use those classes for occasional tags that can??™t be
speci?¬? cally targeted with contextual tag-based selectors??”you won??™t go far wrong.
Pages:
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76