Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

Pseudo Classes

As the only web person in a studio of 6 designers feeling frustrated when no one else gets as excited over pseudo classes as I do. :-(

5 Answers

Am with you. There is so many cool uses for pseudo classes.

Great to experiment with

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Especially the structural pseudo-classes!

Quiet a few to remember now.

Guil what's your thought's using these against classes?

Some say that they would be hard to maintain and not as flexible.

You can now get quiet complex.

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Hi Kevin,

I find myself using the :nth-child() selectors the most, especially for selecting elements in lists.

For example: li:nth-child(odd); or li:nth-child(-n+4);

You don't want to use too many of these in your CSS, however. I agree that some can be difficult to maintain. If you have a rule like the following:

div:nth-last-of-type(2n+8) {  
    background: yellow;
    color: red;
}  

Think of the developer (or yourself) that has to manage this code a few weeks /months down the road. This is when you're better off using a class such as:

.warning {  
    background: yellow;
    color: red;
}  

There might be times when you're dealing with a wild CMS where you can't add certain classes to the markup – that's when these can really come in handy.

Using the nth-child() selectors is really use full.

Agree that there are times you want to stay away from complex selectors. For example for you go back to amend the structure then you need to locate and change the selector. Across a large site then this could be very time consuming. This is the situation I would go with a class.

If I find myself stripping styles then I know something is wrong. I have been taking more time to consider my approach.

Useful links for other members to consider.

Scalable and Modular Architecture for CSS

Harry Roberts post on when you css smells