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 trialGraham Davidson
Courses Plus Student 14,966 PointsPseudo 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
Kevin Esther
8,551 PointsAm with you. There is so many cool uses for pseudo classes.
Great to experiment with
Guil Hernandez
Treehouse TeacherEspecially the structural pseudo-classes!
Kevin Esther
8,551 PointsQuiet 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
Treehouse TeacherHi 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.
Kevin Esther
8,551 PointsUsing 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.