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

Lars Jönsson
Lars Jönsson
2,965 Points

Nth child selector

Hi everybody!

I got a problem, im trying to get some padding on some icons by writing:

    img:nth-child(1n+2)
      @include xlarge
        border: 1px solid black
        padding-right: 5% 

It should add padding as you see. But i dont work. Only by replacing 1n+2 by odd. Then it selects all the elements, and thats not exactly correct either. When i replace odd with even nothing happens.

I know that the code a write first is correct, it must be... or? :D

This is the HTML:

#author-bio
  .place-left
    .author-pic
      img(src="assets/img/3.svg")
    .author-media
      a(href="#")
        img(src="assets/img/facebook.svg")
      a(href="#")
        img(src="assets/img/youtube.svg")
      a(href="#")
        img(src="assets/img/instagram.svg")

And the CSS:

.author-media
  padding-top: 5%
  @include xlarge
    padding-top: 10%
    img
      width: 48px
      height: 48px
      @include xlarge
      width: 38px
      height: 38px
    img:nth-child(odd)
      @include xlarge
        border: 1px solid black
        padding-right: 5%

I want to select img 1 and 2.

I'm using JADE and SASS by the way.

2 Answers

Steven Parker
Steven Parker
230,274 Points

:point_right: The equivalent of "odd" is "2n+1" (not "1n+2").

Lars Jönsson
Lars Jönsson
2,965 Points

Yes, but when i write 2n+1 it selects all the elements.. How is that?

Steven Parker
Steven Parker
230,274 Points

Try checking the compiled CSS, maybe it's not translating into what you expect.