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 Basics (2014) Basic Selectors Reusing Classes

Cuong Hoang
Cuong Hoang
1,769 Points

Confused about classes... So you can assign an element more than one class? such as: <h5 class="min-ha min-ho">

confuzzled!

2 Answers

Yes,

You can assign as many classes as you want to. Just keep in mind that the space is always the seperator. So you cannot have a classname with a space in it. You can style different classes seperately, like:

HTML

<h5 class="min-ha min-ho">

CSS

.min-ha {
background-color: #fd7342;
}
.min-ho {
color: #fff;
}

In your stylesheets, you can also select mulitple classes to assign a styling to different classes at once, like this:

.min-ha,
.min-ho,
.min-hi {
background-color: #fd7342;
margin: 5px;
bottom-border: 1px solid;
}
Cuong Hoang
Cuong Hoang
1,769 Points

Thanks! that was really helpful. And classes applies to all pages other than index.html too right if i styled it in an external css? Also about ID, is this the same if I were to use the same ID across multiple pages? or does it only apply once to a certain page? THANK YOU!!!!

Glad i could help! :)

As long as you link to the stylesheet in your HTML, the CSS will be used on all page you want.

So if you have a stylesheet with

.min-ho {
color: #e5ebab;
}

Every page you link that stylesheet to will use that CSS on the min-ho classes. Does not make a difference if you use ID's or classes, except for the fact that you can use an ID only once in a page. But for the next page, you can use it again, no problem.