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.

CSS Compass Basics Compass Helper Functions Color Helpers

Manu Santana
Manu Santana
8,329 Points

Color Helpers... How can apply the linear-gradient to the rest of li:nth-child with a mixing or similar?

I'd like apply the gradient to the rest of nth-child and I don't know if it's possible.

In this example.

.colors { li { background-color: $base; } li:nth-child(2) { background: adjust-lightness($base, 10%); } li:nth-child(3) { background: adjust-saturation($base, 30%); } li:nth-child(4) { @include background ( linear-gradient($base, shade($base, 50%))); } li:nth-child(5) { background: tint($base, 40%);
}

Thank you in advance

So heres a couple ways. You can select every other child by specifying odd or even within the perenthesis.

li:nth-child(odd) { }
li.nth-child(even) { }

You can also choose every third, sixth or tenth child by using expressions. This one selects every third.

li:nth-child(n3+3) { }

hope this helps.

1 Answer

Manu Santana
Manu Santana
8,329 Points

Dear Nick,

Thank for your answer. But I'm referring to create a mixin or similar to write the code the simplest way. Thanks again.