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 trialTony Brown
Courses Plus Student 1,678 PointsWhy 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.
Marcus Parsons
15,719 PointsPlease disregard what Ryan said.
3 Answers
Joshua Veazey
6,190 PointsHi 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.
Tony Brown
Courses Plus Student 1,678 PointsGot it! Thanks guys!
Ryan Roy
Courses Plus Student 3,586 PointsUnless 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
Marcus Parsons
15,719 PointsYou 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.
John Snow
923 PointsI 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
ericb2
11,429 PointsIn 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.
Ryan Roy
Courses Plus Student 3,586 PointsRyan Roy
Courses Plus Student 3,586 PointsI'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.