Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS How to Make a Website Adding Pages to a Website Build the Contact Page

Tony Brown
PLUS
Tony Brown
Courses Plus Student 1,678 Points

Why are we using class="" instead of id="", if we are only referencing one thing?

Isn't class="" used for referencing multiple things, while id="" is used to reference one thing?

But, we're only referencing one thing here. Is there a benefit to using class over id.

Ryan Roy
Ryan Roy
Courses Plus Student 3,586 Points

I've run into this one before and I read, but I can't recall where, the following. The advice was that id="" is too specific and to avoid using it but to rather add !important when you need to get very specific. I work with developers who use it a lot and some who like me stick to class="".

I'm happy to be wrong however so if someone has a better knowledge please tell us.

Please disregard what Ryan said.

3 Answers

Hi Anthony, In this course, the class is used for a couple of reasons instead of an ID. one, a dot is easier to type. Also, that class could be reused with other html tags saving time, just writing one rule.

Ryan Roy
PLUS
Ryan Roy
Courses Plus Student 3,586 Points

Unless Marcus Parsons has something meaningful to contribute, I found some more information here as well you may find useful. http://css.maxdesign.com.au/selectutorial/advanced_idclass.htm

You said that "id="" is too specific". It is not too specific. That makes it sound like it is too much of something and should be avoided. ID is more specific than class and should be used only on one element. Class should be used on multiple elements that require the same code.

It is much harder to select a specific element by a class than it is by its id.

I was abit confused with this as well. If I was doing this without the help of the video, I probably would have gone for id, not class. After looking at their defintions, it seems id would be more appropiate in this instance. But hey, Nick Pettit knows more than me and he put class so we'll go with that lol

In reference to phone, mail, and twitter links on the contact page of the video, though Nick only created one link for each, you can easily imagine a page with multiple phone numbers, email addresses (and maybe twitter accounts?). In such cases, ID would require additional css code for each new contact link. By using class, new contacts added to the html can re-use the existing class and no changes are required to the css.