views:

220

answers:

3

I have 3 spans inside a div.

  1. text-align:center isn't working (tried on the parent too)
  2. text-align: -moz-center neither (on ff2)
  3. i have to use spans
  4. no floats
  5. -moz-inline-box or -moz-inline-stack ?
  6. with -moz-inline-block it's working but the 2nd and 3rd spans clear left…

Anyone got an idea? (fixing #6 is an alternative)

A: 

Just put some left and right padding on those spans?

So if you have something like this:

<div>
    <span>some text</span>
    <span>also some text</span>
    <span>again here comes some text</span>
</div>

Just use it like this in your css:

span{
padding:0 10px;
}

Result will be something like this:

http://i48.tinypic.com/5knczm.jpg

Note, i added 1px border, so you would see that text is "centered"...

GaVrA
I can't do it cause im using a flexible layout (width in %) > i tried using % or auto and it's not working.
Knu
Then dont use inline element like span. Do it with unorder list.
GaVrA
i tried it but it's not working in my case cause each li with have a different text's length (using % to center with padding and display:inline) and im getting the same result with lis for #5 and #6 (not centered or clears left) / i want all 3 spans on the same line
Knu
A: 

EDIT:

div{
    width:80%;
    display:table;
}
span{
    width:33%;
    display:table-cell;
    text-align:center;
    border:1px solid #F00;
}

Note that both the div AND span width need to be changed to adjust widths. The span should be 100/(no of spans)% and the div whatever width you want.

edl
the width is not respected (shrink to the text width) anymore and ill have to use css hack (cause lte ie7 doesn't support table-cell)
Knu
That's weird.. it works for me on ff2 with width:300px; As far as using table-cell goes, the impression I got was that you only cared about supporting ff2?
edl
try with a width in % / ill use a css hack if it works
Knu
Check out the edits. Its a little hacky, but the best I can come up with.
edl
ok thx wer almost there but now the margin (in %) on the spans isn't working anymore
Knu
A: 

HTML

replace <span>text</span> by <p><span>text</span></p>

CSS

p {display:-moz-inline-stack;text-align:center}
span {display:block}
Knu