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
Benjamin Hedgepeth
5,672 PointsInterpreting the '-1' in nth-child(an+b-1).
I understand fully the short hand nth-child(an+b) expression. The long form expression that has (an+b-1) is what I want to understand. What does the -1 represent?
1 Answer
Steven Parker
243,656 PointsWhere did you see this "long form" displayed?
If you are referring to the definition at MDN where they say "...matches an element that has an+b-1 siblings before it", they're just explaining what the form "an+b" does (when a is not negative).
I'm only familiar with these 4 variations:
- nth-child(a) = element number a
- nth-child(an) = every a elements
- nth-child(an+b) = every a elements starting with b
- nth-child(-an+b) = every a elements ending with b
Benjamin Hedgepeth
5,672 PointsBenjamin Hedgepeth
5,672 PointsI was referring to the (an+b) as the short form and (an+b-1) as the long form. I get the 4 variations that you mentioned. The -1 was throwing me off since it didn't make any sense to me.