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

HTML Introduction to HTML and CSS (2016) Getting Familiar with HTML and CSS Building Web Pages with HTML and CSS

I am confuse about classes

When you set the names of the classes <h1 class="tag name"> and <p class="tag location"> they start with tag. And when you do in style.css instead to do .tag name or .tag location you only did .tag. My question is which did you target tag name or tag location? Becuase I thing in can better in this way tag-name and tag-location.

3 Answers

Nicholas Vogel
Nicholas Vogel
12,318 Points

If there's a space between the words in your class, that means there are multiple classes. For example, class="tag location" has the class .tag and .location. In order to target both classes, you would use .tag, and the other tag would be to target the specific element with either .location or .name.

andren
andren
28,558 Points

The answer is that both the h1 and the p were targeted. The class attribute is a list of classes separated by a space. Meaning that a class of "tag name" actually means that you assign two classes, the class "tag" and the class "name". "tag location" assigns the class "tag" and the class "location".

Therefore by targeting the tag class in CSS both of the elements were targeted, because they both have a tag class.

The fact that you can assign multiple classes to a single element and the same class to multiple elements, is part of what separates classes from IDs, and is part of what makes them so useful.

Martin Čierny
Martin Čierny
1,344 Points

I got confused on that too, but just because I cant see .name class in in the CSS file. I might be blind, correct me if Im wrong but I dont see it there... If I removed .name class from H1 tag nothing happened, but if I removed .tag class from P tag, the webpage got messed up :)