3 replies [Last post]
dcaverman
dcaverman's picture
Offline
newbie
Last seen: 6 years 7 weeks ago
Timezone: GMT-5
Joined: 2014-05-28
Posts: 7
Points: 11

I've been going through a book along with online examples to dig into CSS. I'm not exactly sure when use

versus
. Most of the examples I've seem to use ID but a friend of mine that is trying to help me implied that I shouldn't really use ID.

I was thinking that if I knew it was a unique

on say one page then you would use ID. Example: with a MasterPage I would put
around the ContentPlaceholder. On the flip side if it's something that would be used in multiple places like a page title you would use a class.

What do most people use as a rule of thumb?

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 5 hours 15 min ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9761
Points: 3843

You have it right

An id must be unique, it's like a social security number; it applies to one person only. A class is just that; any number of elements may belong to a class. For example, an individual may be addressed by his name and only that person responds. Likewise you might address redheads, in which case any number of people might respond.

Using a class token when an id is more proper is a waste of bits. The browser continues to look through the entire document for the class token. If you address an id, the browser stops once it is found.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

dcaverman
dcaverman's picture
Offline
newbie
Last seen: 6 years 7 weeks ago
Timezone: GMT-5
Joined: 2014-05-28
Posts: 7
Points: 11

Thanks, that makes sense. So

Thanks, that makes sense.

So in one of my scenarios I have a Master Page with

that has a width=800px and margins set to make it centered. Since this is the only place I will use or reference AllContent then I should use it as a ID and not a class.

CupidsToejam
CupidsToejam's picture
Offline
Guru
Florida
Last seen: 4 years 48 weeks ago
Florida
Timezone: GMT-4
Joined: 2008-08-15
Posts: 2637
Points: 1556

yes

yes