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
Alexey Tseitlin
5,866 PointsCant get “nth-last-child” to work
Trying to apply styles to all of the elements except the last one. But it doesn't work.
ul {
list-style: none;
margin: 0;
float: left;
width: 100%;
text-align: center;
}
ul li {
height: 54px;
width: 54px;
border-radius: 60px;
}
/* /// THIS PART IS NOT WORKING PROPERLY
RIGHT NOW IT REMOVES MARGIN FOR ALL THE ELEMENTS/// */
ul li:not(ul li:nth-last-child) {
margin-left: 10px;
}
.red {background: #fc4c4f;}
.blue {background: #4fa3fc;}
.yellow {background: #ECD13F;}
<ul>
<li class="red selected"></li>
<li class="blue"></li>
<li class="yellow"></li>
</ul>
2 Answers
Ayoub AIT IKEN
12,314 PointsHey !
simply cause you mustnet write the (nth) , just write the last-child pseudo class !
geoffrey
28,736 PointsHey there !
ul li:not(:last-child) { /* this will target all <li> nested inside ul except the last one, the last-child*/
margin-left: 20px;
}
ul li:last-child { /*this will only target the last <li> inside <ul>.*/
margin-left: 20px;
}