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.