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 CSS Basics (2014) The Box Model Margins

Width and auto margin

So my question is the following.

We saw in earlier videos that Guil set the width of the container to be 60% of the total width.

When he set the margin to auto did that override the CSS rule for the width to be 60%

1 Answer

Jaime Gonzalez
Jaime Gonzalez
8,359 Points

No, the margin auto all it did was center the container.

For example lets say the page is 100px wide and inside there we have a container that has a width of 60% of the page so, 60px.

Currently the container is sitting towards the left with 40px of nothing on the right side of the container. If we set 'margin to auto' it will center the container on the page putting 20px of margin on the left side and 20px on the right side.

The container will still be 60% wide.

Hope this helps, sorry if it's more confusing.