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 trialPeter Huang
5,427 PointsWhy do we use class="form-contact" instead of just simple class of " .form-contact " ?
Why do we use class="form-contact" instead of just simple class of " .form-contact " ?
Is this something you MUST use on forms for it to work and regular class will not work? I dont understand this
1 Answer
Steven Parker
231,275 PointsIt sounds like you stopped your video early, or just missed the part at about 5:26 where the instructor says:
Well, now you may be asking, why target elements with attribute selectors instead of the classes or ids we learned about earlier. Well, most of the time there's no real advantage to using these attribute selectors when it comes to targeting ids and class attributes. It's usually best to use a class or id selector, in this case.
He then makes those changes to the stylesheet, and then goes on to show a more practical example of using an attribute selector to look for an element with a particular type.
Peter Huang
5,427 PointsPeter Huang
5,427 PointsThank you for this. Yes I've stopped video early to ask which is a bad habbit of mine. I just got another question though, is this method only good to target specific form bar type area and change color? he goes on to teach these but I don't see the difference in still using the regular class or ID to target these
Steven Parker
231,275 PointsSteven Parker
231,275 PointsAn ID can only target one element, so it's not useful when more than one is involved. And using the type attribute to target elements would be advantageous when they don't all share the same class (or if there are other elements with the same class that you don't want included).