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

General Question About the Understanding of Classes

If classes such as class="selected" or class.hover are not predetermined classes and i can enter whatever i wish, much like an ID, how is it affecting the state of th link based on the class value i have entered? Hopefully that makes sense.

2 Answers

Steven Parker
Steven Parker
231,269 Points

It sounds like you are talking about pseudo-classes, which are indicated by a colon (not a period) such as class:hover.

These do not affect the state of the link, but they respond to the state. For example, if you have a link named "foo" and a selector foo:hover, when you move the mouse over that link, the selector will apply the property values to that element. When the mouse moves away, those property values will not be applied.

Note that pseud-classes don't have to be used with actual classes. For example: a:hover would create a hover behavior for every link in the document.

Thanks Steven! Ha i worded my question horribly. I understand that it responds to the state and doesn't create it or change it. However, I'm still confused about the way a "custom" psuedo class knows that it is in that state. Hopefully this makes sense. For instance, in my index file when i set a psuedo class to a nav like class="selected" it sounded like Nick was saying i could say class="currently on this page" and it would still know that it is selected. (i just learned this so i think its a psuedo class)

Nick said i could call "selected" anything because it is not a predetermined class... yet I feel like "selected" should be somehow predetermined. Did i just completely misunderstand what he said?

Shane Oliver
Shane Oliver
19,977 Points

The class name "selected" isn't a pseudo element, it's a class name used to add styling to elements that have been selected. When he says you can choose any name, he means the name 'selected' works for him but since it's not predefined you can name the class anything that makes sense to you. For example, 'chosen', 'ticked' or whatever other adjective makes sense to you as the class name.