Jump to content

Class or IDs


youngros

Recommended Posts

I'm sure the others will have differing opinions, but basically, I use IDs for everything that will be unique in my site. For example, I only have one main menu so I'll use an ID for that. For the things that will recur in my site (boxes, styles, etc), I use a class.

Link to comment
Share on other sites

I'm sure the others will have differing opinions....
It's not a matter of opinion - that is the proper, intended use. IDs for anything that only shows up once, and classes for stuff that's used more than once - on any given page (not site).
Link to comment
Share on other sites

I try to use as few IDs as possible, but use them when necessary.

 

For instance, I might have a header, a navbar, a content area, and a sidebar on a site. Each of those divs would have an ID, and everything under it would have either a class, or nothing. I would assign another id if I had a discrete content object - like a Coda slider, or something.

Link to comment
Share on other sites

what is a Coda slider?

 

It's a javascript effect, made popular by the Coda website. An example of the effect is here: http://www.ndoherty.com/demos/coda-slider/1.1.1/#1

 

As most people are saying, I usually organize my code something like this:

 

 

The main divs that stay consistent on every page use id's, and anything inside those main divs use classes.

Link to comment
Share on other sites

You should be using IDs whenever possible. It makes the page more robust and you have control of the elements, two parts of the site may use the same class but it does not work in one or the other so you then need two classes. If the class is in different IDs then it can look slightly different in each. So ID's allow you more flexibility and they can be used with not just CSS but in scripts and programming too. The best sites are those built almost exclusively of IDs. I rarely ever use classes as I can do more with IDs.

 

IDs may only exist once on a page. Classies can be used often on a page.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...