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 trialsibal gesekki
3,484 Pointswhy not make everything class instead of id
id seem useless to me. ok cool i can only use id once. but i can use class one time OR many times. class seem better to me. if make everything class, then dont have to worry wether to use id or class. pls help thank
3 Answers
Ken Alger
Treehouse TeacherSibal;
Welcome to Treehouse!
There are definite reasons for using id
. Take a look at this article over at css-tricks.com. It might shed some light on a few possibilities.
Happy coding,
Ken
Scott Peake
17,052 PointsGood point you brought up too... "hard to know is I am only going to style an element once or many times"
Elements can have BOTH an id and a class. In fact, a single element can have MANY classes; simply include inside the quotes, separated with spaces.
<div id="good" class="luck sibal">Study Hard</div>
#good {
font-size: 10px;
}
.luck {
text-align: center;
}
.sibal {
color: steelgrey;
}
There are lots of really good CSS lessons in the library.
Scott Peake
17,052 PointsHey Sibal!
Actually, there are DRAMATIC differences in their usage, and it mostly comes down to how specific you want to be. Obviously, classes are intended for "groupings" of code while ids specify a "unique" element. Sure, there are many powerful CSS selectors (http://www.w3schools.com/cssref/css_selectors.asp) that will allow you to pick through your code (written using only classes) to select one particular element in code for styling, but syntax is complex (i.e., prone to coding goofs).
The use of ids also becomes more important when you start using forms and server-side languages.
Keep up the good work! And keep an open mind on ids!
sibal gesekki
3,484 Pointsscott, thanku. i will try use id when i only style a element once and class when style many element. it just hard for me to know if i only going to style element once or many time. i hope be full stack developer one day but lots of things to know at once
sibal gesekki
3,484 Pointssibal gesekki
3,484 Pointsken, thanku. but link i think is broken?
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherSibal;
Thanks for pointing out the link issue. Please take another look.
Ken