4

This code will work fine in Webkit (chrome) but not in firefox, where the second span will drop, do you know why?

<div id="sbar">
    <span id="status">Some Text</span>
    <span id="mlog" style="float: right;">Some text in the right</span>
</div>
Rex M
  • 142,167
  • 33
  • 283
  • 313
Vasco Fernandes
  • 688
  • 1
  • 4
  • 11

5 Answers5

5

Try reversing the two spans.

<div id="sbar">
    <span id="mlog" style="float: right;">Some text in the right</span>
    <span id="status">Some Text</span>
</div>
jonnii
  • 28,019
  • 8
  • 80
  • 108
1

Can propose other solution without reversing. It does work in different browsers

<div id="sbar" style="position:relative;">
    <span id="status">Some Text</span>
    <span id="mlog" style="position:absolute; top:0;right:0;">Some text in the right</span>
</div>
Roman Podlinov
  • 23,806
  • 7
  • 41
  • 60
1

Yeah... reversing makes it work cause with floats, you need to arrange your elements like a stack that the browser can pick up -

so when floating left

A

B

C

will float to ABC -

A

AB

ABC

when all floated right will give you CBA, as in

A

BA

CBA

I've seen this implemented in firefox, haven't checked webkit. You can be safe with this, though.

Sudhir Jonathan
  • 16,998
  • 13
  • 66
  • 90
1

This code will work fine in Webkit (chrome) but not in firefox

WebKit is wrong. The standard specifies the right-float must go down a line.

For explanation, see CSS: Three Column Layout problem.

Community
  • 1
  • 1
bobince
  • 528,062
  • 107
  • 651
  • 834
1

This code will work fine in Webkit (chrome) but not in firefox, where the second span will drop, do you know why?

Yes. The behavior of a floated element will fall below a non-floated element that comes before it in the code. Others have given you the fixes already.

Traingamer
  • 1,438
  • 8
  • 9