tags:

views:

39

answers:

4

Hey there, 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

{anchor}

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

A: 

Try text-align: left;

Paul Sheldrake
yes but i need to center all the links inside a div
webmasters
i have a div, and i need the links to be centered, but all of them be like in the first order
webmasters
A: 

Do this: nest a left-aligned div in a center-aligned div.

<div style="text-align:center">
    <div style="text-align:left; width:300px;">
        Content<br />
        Longer Content<br />
        Really long Content<br />
        Content<br />
        Content
    </div>
</div>

Addition:

CSS lovers everywhere will condemn me for suggesting that you could replace the inner div with a table, which would remove the need to specify a fixed (or percentage) width.

kbrimington
A: 

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

Ian Wetherbee
thought of that myself, but i cant use fixed width
webmasters
See here for dynamic widths: http://matthewjamestaylor.com/blog/beautiful-css-centered-menus-no-hacks-full-cross-browser-support
Ian Wetherbee
A: 

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.

meder