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 CSS: Cascading Style Sheets Style the Basic Elements

Jozef Bobek
Jozef Bobek
2,248 Points

#wrapper { margin: 0 auto; max-width: 940px; } Why does this command not work as an answer?

I'm not sure how to resolve this step 2 of 3.

css/main.css
#wrapper {
  margin: 0 auto;
  max-width: 940px;
}

Q; Challenge Task 2 of 3

Select the ID wrapper, set it to a max width of 940 pixels, and then center it on the page using the margin property.

3 Answers

Jozef Bobek
Jozef Bobek
2,248 Points

Both options passed the challenge. The note I COMPLETELY missed during my attempt was this:

Important: The code you write in each task should be added to the code written in the previous task.

This passes for me:

#wrapper {
 max-width: 940px;
 margin: 0 auto;
}

So for part 2 of the challenge you should have the following:

a {
 text-decoration: none; 
}

#wrapper {
 max-width: 940px;
  margin: 0 auto;
}

The first portion being from step 1 of the challenge.

missgeekbunny
missgeekbunny
37,033 Points

CSS is very particular about order. You can't set 2 auto margins without it having a width first. Since you set the width after calling the margin the margins didn't have a width to work with when it ran and so it did nothing.

That's inaccurate, actually.

#wrapper {
 max-width: 940px;
  margin: 0 auto;
}

works just the same as

#wrapper {
margin: 0 auto;
 max-width: 940px;
}

You can run it as a test on http://codepen.io to see it in action.

missgeekbunny
missgeekbunny
37,033 Points

Well it would seem that for the code challenge it wants it the other way since that is the only difference between his code and the code you gave him. I'd probably still get in the habit of setting the width before setting auto margins. At very least you know so you know you have a width before you expect it centered.