Floating span: Cross-browser display issue

Discussion in 'HTML & Website Design' started by James WP, Jan 20, 2010.

  1. #1
    I have the following code on my site (simplified):

    <div align="left">Text on the left
    <span style="float:right;">Text on the right</span>
    </div>
    Code (markup):
    In Firefox and Chrome, the two pieces of text appear on the same line, but aligned to opposite ends. This is good. In IE however, while still aligned at opposite ends, they appear on separate lines (the second piece of text on the line below).

    Can anyone help it display properly in Explorer, as it does in the other browsers? I'm sure I could use tables instead, but the rest of the design has avoided them for layout so far.

    Many thanks.
     
    James WP, Jan 20, 2010 IP
  2. harrierdh

    harrierdh Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not do this?
    
    <div>
    	<span style="float:left">Text on the left</span>
    	<span style="float:right;">Text on the right</span>
    </div>
    
    Code (markup):
     
    harrierdh, Jan 20, 2010 IP
  3. James WP

    James WP Active Member

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    That seems to create new problems of its own.

    The DIV actually has a background style, which better illustrates what's going on if anyone wants to recreate the problem:

    <div align="left" style="background-color: #E4E7EA;">Text on the left
    <span style="float:right;">Text on the right</span>
    </div>
    Code (Original):
    <div style="background-color: #E4E7EA;">
    <span style="float:left;">Text on the left</span>
    <span style="float:right;">Text on the right</span>
    </div>
    Code (harrierdh's suggestion):
    In all three browsers, using the two-SPAN approach results in the DIV's background color disappearing.
     
    James WP, Jan 20, 2010 IP