Printable Version of Topic

Click here to view this topic in its original format

Forums _ Webmasters' Corner _ div id Vs. div class

Posted by: spambot Sep 23 2010, 11:19 PM

When is it proper to use a id verses a class? and the other way around?

It's been ages since I have looked at any kind of code so help a n00b out?

Posted by: mipadi Sep 24 2010, 01:32 AM

IDs are supposed to be unique per-page. You use an ID to describe a unique element on the page; you use a class to describe items that are generic and non-unique.

Take the front page of a blog, for example: the header would probably be div#header, whereas each blog post may be encapsulated as the div.blog-post class, since there are several of them and it's a generic container.

Posted by: ButtsexV2 Sep 24 2010, 04:02 PM

I had no idea that there was actually a proper time to use an ID vs a class.