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 Display Values

Kamil Zak
Kamil Zak
5,104 Points

Why sometimes is text-align not working?

It's like something is blocking it, links we added class to didn't move to the center of the page. I tried text-align but didn't work, margin-left works just fine.

Ezra Siton
Ezra Siton
12,644 Points

Don't "MIX-UP" - text-align: center - is a CSS property. This is not like saying "center to the page".

It always works (like in word or any other text editor) - but sometimes you have CSS conflicts or (most of the time) you trying to align an element to the right (but you declare this as inline!! or inline block) - and this is an issue (endless tricks to solve this - flex/float/position/and so on) **H1-6, P are block level elements

h1{
    text-align: right; 
    display: inline;    
/* No change */
}

2 Answers

Text-align will center an object within the box you create for it. Try adding a margin that fills the page horizontally, and then centering the text within that. Im using the <p> tag as an example:

p {
  margin: 0 auto;
  text-align: center;
}
Kamil Zak
Kamil Zak
5,104 Points

Thank you, Joseph and Ezra. Now I understand it, my CSS was a mess and I didn't see the conflict.