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 The Selectors Solution

Magdalena Misiuna
Magdalena Misiuna
14,873 Points

I can not find a solution to make every 2nd letter in the heading a different color. Could you help?

I know I saw this in one of the CSS SElector tutorial, but can not find it :(

3 Answers

Steven Parker
Steven Parker
231,275 Points

Only the first letter has a pseudo-class (:first-letter), so to style others you'll need to enclose them in an element like "span". For example:

<h1>S<span class="L2">a</span>mple heading</h1>
.L2 { color: red; }
Magdalena Misiuna
Magdalena Misiuna
14,873 Points

I was hoping there is a way to avoid placing <span> on every second letter. Thank you so much for your help!

Steven Parker
Steven Parker
231,275 Points

There isn't currently. But there is a proposal for future CSS versions to have a ":nth-letter" pseudo-class that would do the trick!

Happy coding!

Magdalena Misiuna
Magdalena Misiuna
14,873 Points

:nth-letter, it would be a perfect solution! Thank you again.