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

HTML How to Make a Website CSS: Cascading Style Sheets Center the Wrapper

Luke Svarc
Luke Svarc
1,338 Points

wrapper width and margin not changing?

Hi,

I have added the <div id="wrapper"> </div> to my html and have then added the following CSS to as per the video

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

Code here: https://w.trhou.se/gq4tw3hdo2

However when I save and preview it doesn't seem to have shifted my content as expected.

Can anyone advise?

Thanks

2 Answers

Billy Bellchambers
Billy Bellchambers
21,689 Points

Hi Luke,

The code you have written is fine and working as expected.

I think the issue is that you img's are not containing themselves inside the wrapper and currently breaking out of this div.

The following code should restrict the img's to there parent element.

img {
  max-width: 100%;
}

Additionally sometimess changing the background color of a div element when you are manipulating it with css and its not working as expected can help to see the issue.

As you code was indeed restricting the wrappers size, and was just the img not playing nicely.

Hope this helps.

Happy coding!

Luke Svarc
Luke Svarc
1,338 Points

Hi Billy,

Thanks for the help.

I have added in the suggested code to my CSS and still see no changes in the positioning of my the div wrapper.

I've tried playing around with the max-width and margin settings but nothing seems to move it?

Any ideas?

Thanks again

Luke Svarc
Luke Svarc
1,338 Points

Hi,

It is working now. I think it was a browser problem, closed down, restarted, added code etc. and now it works!

Thanks again.

Billy Bellchambers
Billy Bellchambers
21,689 Points

No worries.

Glad its working now for you