Jump to content

A pet peeve ID vs Class


grabenair

Recommended Posts

This has been touched on a few times. Sorry, but I am going to again. As a beginner it is easy to get caught making everything a class. This is bad practice. To avoid another real long rant on my part I am going to give you some reading on this subject. I hope this is ok? If not I am sure Andrea will zap me.

 

w3schools has the basic http://www.w3schools.com/css/css_id_class.asp

 

tizg has a good article http://www.tizag.com/cssT/cssid.php

 

css-tricks has a very good article http://css-tricks.com/the-difference-between-id-and-class/

Edited by grabenair
Link to comment
Share on other sites

Most of the time I do just use classes. I will use ID's if it is something I absolutely know is only going to occur once on the page. .

 

That's how it's supposed to be.

 

I don't know JavaScript, so I cannot comment on what you said about that.

Link to comment
Share on other sites

I have wrote a long explanation on use id or class but LSW is a lot better writer then I. So I am going to refer you two to his article.

 

http://www.killersites.com/community/index.php?/topic/75-two-basic-css-mistakes/

 

Also it must have been ok for me to post the links that I did because Andrea did not zap me, please read.

 

Seance I started web designing four years ago, I know not very long, every tutorial paid or free and books that I have read goes into this. IT is much better practice to us id's over classes. Only use classes if you need to.

 

My intent is not to make Andrea or benjaminmorgan mad, I apologize to you both ahead of time if I have. My intent is to help newbies to writing css to use good practice to start off with because it is hard to change a bad habit.

Link to comment
Share on other sites

My intent is not to make Andrea or benjaminmorgan mad, I apologize to you both ahead of time if I have. My intent is to help newbies to writing css to use good practice to start off with because it is hard to change a bad habit.

 

Helping and providing info is what this is all about.

 

The ID vs. class thing really is simple. If something only happens ONCE per page, use IDs, if more than once or if you're not sure yet, use a class. Things like header, footer, navigation are usually pretty sure bets of only appearing once.

 

HTML5/CSS3 will take care of that issue, since 'header' will be neither id nor class, just <header>

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...