CSS CSS Layout Basics Getting Started with CSS Layout Using a Mobile First Approach

Maya Shen
Maya Shen
7,056 Points

How did the .main-footer {text-align: center;} make all container centered in this page?

I notice there is no center property in .container to align contents of header and section in center of their parent box. Only text-align: center was set in main-footer. And in my practice followed the steps in this tutorial, the contents of header and section lay on the left.

Andrei Duhanes
Andrei Duhanes
14,155 Points

The reason he used text-align:center to center the text in the footer is because it's full width of 100%. The container has 70% width so the way to make it center is to add margin: 0 auto like this.

.container { width: 70%; margin: 0 auto; (meaning it distributes equal space left and right to create a margin of 30%) }

This does not mean all the text within the container will be exactly in the middle ( only the container including the text). If you add:

.container { width: 70%; margin: 0 auto; (meaning it distributes equal space left and right to create a margin of 30%) text-align: center ( every text will be centered within the centered container ) }

Hope it helps!