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

Tushar Singh
PLUS
Tushar Singh
Courses Plus Student 8,692 Points

li:last-child

I have my borders on list items in navigation and wanna remove the border from the last item. When I use the last child pseudo class, it just removes all the borders. codepen--my css is not good.

nav ul li {
  display:inline-block;
  padding:20px;
  border-right:1px solid white;
}
nav ul li:last-child {
  border:none;
}

2 Answers

Matthew Ellis
Matthew Ellis
12,303 Points

Hi Tushar,

Looking at your Codepen, it looks like you have your <a> tags outside of your <li> tags.

ie.<a href=#><li>HOME</li></a>

Try:

<li><a href=#>HOME</a></li>

Steven Parker
Steven Parker
231,007 Points

I was going to say you could apply last-child to the a element instead, like this:

nav ul a:last-child li {
  border: none;
}

And that works, but then there really shouldn't be any direct children of a ul other than li's. So go with Matthew's suggestion.

BTW, are you getting a little behind in choosing "best answer"s for your previous questions? :wink:

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

Well you din't solve my that problem :stuck_out_tongue: . Nobody has an answer for me regarding that game :weary: . Only you can do this :wink:, Please help me . I am literally stuck and don't know what to do :sob: