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 Review: CSS: Cascading Style Sheets

songbeizhang
songbeizhang
970 Points

Margin declaration

Does the margin: 0 auto; means that the wrapper element is centered inside the browser window no matter how large the browser gets?

1 Answer

Hello Songbei,

in order to center an html element with margin: 0 auto, the targeting element has to be a block element and it must have a fixed width or a max-width. For example, the css of the element you want to center, it has to be: .element { display: block; width: 320px; or max-width: 320px; margin: 0 auto; }. So, no matter how large the width of the browser gets the targeting element will always be centered with width 320px.

Hope you find it, helpful! Take care

songbeizhang
songbeizhang
970 Points

Thank you for the reply. I figured the same, but your answer helped to clear things up more!