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!

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


Dani Ivanov
Dani Ivanov
10,732 Points

Centering links within a div


I've been working on a project of my own and I'd like to know this:

In this example http://jsfiddle.net/BDt6U/

If I apply the text-align: center property to the .linksWrapper a declaration, then the links will not center. However, If I apply the text-align center to the .linksWrapper, the links will center.

My logic, and I am probably wrong, is that I should apply the center property to the links themselves since I want the links to center, but I found out that this is not the case.

Regards, Dani

1 Answer

Tom Bedford
Tom Bedford
15,645 Points

Hi Dani

If you apply text-align center it to just the anchor tags then it will center text within each individual tag. If you set a large width for the anchor tags you can see how the text positioning works inside them. By applying the centering to the div you are centering the position all text (which includes the links) that are within that div. Even if they are centered in the div you can still align the text in each anchor tag separately.

If you have a set of links that you are displaying together it is common to organise them in a list.

I've edited the fiddle to illustrate the different aligning settings and show the list method.