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 CSS Selectors Selectors - Beyond the Basics Attribute Selectors

Andre Kucharzyk
Andre Kucharzyk
4,479 Points

Why use [class = "form-contact"] {...}instead of .form-contact {...}

Why use [class = "form-contact"] {...}instead of .form-contact {...}

1 Answer

affash
affash
9,152 Points

well from my understanding you should not use [class = "form-contact"] and instead you should use .form-contact because [class = "form-contact"] affect the performance and make the browsers searches for each class selector i hope that is the right answer if there is something wrong someone can correct me .

Trevis Kelley
Trevis Kelley
Courses Plus Student 3,777 Points

I believe you are right, and given that info, why wouldn't I just assign a class to all of my different form elements? For example, give all e-mail address entries a class of "email", and then just select the "email" class in the CSS. I add ids and classes to every entry I make in my HTML just so that I can all the way from very broad to very specific. This type of selector seems to be very redundant or just not a good method. Unless there is something I am missing (which, to be fair, is almost always the case with me). If someone could clarify why the instructor says it's good for form elements, that would be great! Otherwise, I really don't understand why we would learn/use this method.

Kjetil-Lennart A. Lorentzen
Kjetil-Lennart A. Lorentzen
13,390 Points

I'm learning, just like you guys. So don't scold me if i'm wrong here, haha. I think it's unneecessary to create a class for the e-mail form if it's the only one that's going to have the styling. And maybe it's good to not make an ID because it fills up and makes the HTML "longer"? So it's a way to distribute and keep things clean? This is atleast what i got from this.

And anyway; It's a course on CSS selectors, so it's good that we get to learn about it, because it's a way of doing it. It wouldn't be an awesome course if you heard about this later, saw a use for it and go "Teamtreehouse didn't teach me this."

I understand that you're confused, because so am i, but i'm guessing answers will come in later videos.