Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS

Dani Ivanov
Dani Ivanov
10,732 Points

Centering links within a div

Hello,

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.