Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS, centering links inside div

Tags:

css

how can I center my links like this? They all are centered inside a div, but they begin from the same distance.

i am link 1
i am a longer link than link 1
i am a short link
we are all centered in div

If I apply text-align: center, I get:

         i am link 1
i am a longer link than link 1
      i am a short link
   we are all centered in div

Thank you ;)

I have a table:

<td valign='top'><a href='{url}' title='{title}' target='_blank'>{anchor}</a></td>

The links need to be centered in my way, each in its own td. Not sure it's possible.

like image 433
webmasters Avatar asked Aug 03 '10 17:08

webmasters


2 Answers

Wrap the links in another <div style="width: 300px; margin: 0 auto;"> to group them together.

http://jsfiddle.net/NcEpe/1/

Edit for dynamic widths: http://matthewjamestaylor.com/blog/beautiful-css-centered-menus-no-hacks-full-cross-browser-support

like image 50
Ian Wetherbee Avatar answered Sep 20 '22 14:09

Ian Wetherbee


If you need shrinkwrapped centering, apply inline-block on the things you want centered. Then text-align:center; on the parent.

You'll need to probably have a workaround for IE, but as you haven't posted code I won't go into that.

like image 43
meder omuraliev Avatar answered Sep 19 '22 14:09

meder omuraliev