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 CSS Foundations Advanced Selectors Pseudo-Classes: :nth-child

Oliver Sewell
Oliver Sewell
16,425 Points

create a new rules that targets the last 3 elements in the list nth child quiz

what have i done wrong ? T__T

index.html
<!DOCTYPE html>
<html>
<head>
    <title>Structural Pseudo-classes</title>
    <link rel="stylesheet" type="text/css" href="cc1-main-style.css">
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <ul>
        <li>List item 1</li>
        <li>List item 2</li>
        <li>List item 3</li>
        <li>List item 4</li>
        <li>List item 5</li>
        <li>List item 6</li>
        <li>List item 7</li>
    </ul>
</body>
</html>
style.css
/* Write your CSS below */
li:nth-child(even) {
  color: white;
  background: black;
}

li:nth-child(3) {
  background-color: #FF6347;
}

li:nth-child(-n+4) {
  font-weight: bold;
}

li:nth-lastchild(-n+3) {
  font-size: 30px;
}

2 Answers

First you have to set just the color and background of all the <li> from <ul> elements So your code should look like this in the css file:

ul li {color: white; background-color: black;}

Then you have to set the third child background to the value 'FF6347':

ul li:nth-child(3){background-color: #FF6347;}

Then set the first 4 elements to font-weight: bold

ul li:nth-child(-n+4){font-weight: bold;}

And finally change the last 3 elements font size:

ul li:nth-child(n+3){font-size: 30px;}

You can check this link for more useful information: https://css-tricks.com/useful-nth-child-recipies/

Oliver Sewell
Oliver Sewell
16,425 Points

Thankyou so why do we use ul li:nth-child(n+3){font-size: 30px;} and not li:nth-lastchild ?

I prefer to use it that way but will work perfectly well this way too "ul li:nth-last-child(-n+3)"

Keep coding