How may I align text to the left and text to the right in the same line?

后端 未结 9 949
醉梦人生
醉梦人生 2020-12-12 12:37

How can I align text so that some of it aligns to the left and some of it aligns to the right within the same line?

This text should be left-aligned

相关标签:
9条回答
  • 2020-12-12 13:33

    While several of the solutions here will work, none handle overlap well and end up moving one item to below the other. If you are trying to layout data that will be dynamically bound you won't know until runtime that it looks bad.

    What I like to do is simply create a single row table and apply the right float on the second cell. No need to apply a left-align on the first, that happens by default. This handles overlap perfectly by word-wrapping.

    HTML

    <table style="width: 100%;">
      <tr><td>Left aligned stuff</td>
          <td class="alignRight">Right aligned stuff</td></tr>
    </table>
    

    CSS

    .alignRight {
      float: right;
    }
    

    https://jsfiddle.net/esoyke/7wddxks5/

    0 讨论(0)
  • 2020-12-12 13:39

    ​HTML:

    <span class="right">Right aligned</span><span class="left">Left aligned</span>​
    

    css:

    .right{
        float:right;
    }
    
    .left{
        float:left;
    }
    

    Demo:
    http://jsfiddle.net/W3Pxv/1

    0 讨论(0)
  • 2020-12-12 13:41

    <p style="text-align:left;">
        This text is left aligned
        <span style="float:right;">
            This text is right aligned
        </span>
    </p>

    https://jsfiddle.net/gionaf/5z3ec48r/

    0 讨论(0)
提交回复
热议问题