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

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
216,012 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
216,012 Points

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