Jump to content

usage of class n id


nidhi

Recommended Posts

can anyone tell me when to use class and when to use id?is id also used to apply our style? class can b used any no. oftimes that i knw, n i think id can used once. what other differencesare there bw class n id?

Link to comment
Share on other sites

That is correct one difference between those. IDs are not allowed (at least not in Xhtml strict) to be more than once. Classes do.Second, in your stylesheet, classes begin with a dot: .And IDs with a hash: #Like this:

p.common { ... }p#myfooter { ... }

So you'd use classes when you have commmonly used elements, or different elements, that you want to have the same style. Or IDs, when there is only one of them (but then you may still choose for a class). Next, IDs may come in handy when an element already has a class, but still needs more difference from the other elements with the same class. Like in this:

p.common { ... }p.common#first { ... }
Edited by Dan The Prof
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...