CSS CSS Basics 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
6,623 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.