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 Center the Wrapper

Center the wrapper

Hello!

" margin: 0 auto;" does not seem to be affecting my page at all. The items in <div> are not being centered.. am I doing something wrong?

a {
  text-decoration: none;
}

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

4 Answers

I figured it out. Once i got rid of the space between 940 and px (so it became 940px), it was fixed.

Hi!

I hope I understood correctly the result you're getting and the one you want. If not, my apologies in advance.

"margin: 0 auto" will center your wrapper DIV on the page (or the wrapper's parent element), not the elements within it, if you want to center the elements within the DIV you can use "text-align: center".

Let me know if that's what you were looking for.

I wasnt looking for text-align, just margin:0 auto. I just didnt put a space in the width. I had the width set to "940 px". I had to remove the space and make it "940px". Once I did that, "margin:0 auto" worked!

Thanks for your help Mireille

Cool! So I DID misunderstand your question (douh!) Sorry about that. I'm glad you found the answer yourself.