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 How to Make a Website Responsive Web Design and Testing Adjust the Profile Page and Header

Andrew Zhao
Andrew Zhao
3,267 Points

What is the rule for spaces and line-breaks ~in~ CSS code?

In particular, I noticed that my nth-child rule didn't work when I included a space before the parentheses. See below:

  #gallery li:nth-child (4n) {
    clear: left;
  }

The above DID NOT WORK. I had to remove the space before the parentheses to get it to work. So what's the rule in CSS code - when is a space OK to add, when is it not?

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Andrew,

Spaces can be added between element names in selectors, after the colon when declaring properties and pretty much anywhere before and after an selector. The reason why nth-child doesn't work with a space is because the W3C specification doesn't allow for lazy pseudo function matching meaning it only matches against absolute declarations.

Hope that helps.

Andrew Zhao
Andrew Zhao
3,267 Points

Thank you humbly, Chris. :)