Float div's to the right in left-to-right order?

后端 未结 4 1459
太阳男子
太阳男子 2020-12-13 08:45

I have multiple div\'s I want to display in a horizontal row. Normally, the way I\'d do this is to simply float them to the right and put them in the markup in reverse order

相关标签:
4条回答
  • 2020-12-13 09:11

    You could give float: right to the outer div. And the display style of the inner div is inline-block

     <div style="float: right" >
          <div style="display:inline-block">Left</div>
          <div style="display:inline-block">Middle</div>
          <div style="display:inline-block">Right</div>
     </div>
    
    0 讨论(0)
  • 2020-12-13 09:14

    You could apply a text-align: right to the container and a display: inline-block in place of the floating:

    <div style="text-align: right">
      <div style="display:inline-block">Left</div>
      <div style="display:inline-block">Middle</div>
      <div style="display:inline-block">Right</div>
    </div>
    

    DEMO

    0 讨论(0)
  • 2020-12-13 09:17

    Using display:inline-block might not work as expected with elements of variable height.

    So you might want to use:

    <div style="float: right">
          <div style="float:left">Left</div>
          <div style="float:left">Middle</div>
          <div style="float:left">Right</div>
    </div>
    

    See: demo of both -- inline and float-float.

    0 讨论(0)
  • 2020-12-13 09:18

    Float your elements to the left.

      <div>
        <div style="float: left; position: relative; width: 200px;">Left</div> <!-- dummy width -->
        <div style="float: left; position: relative; width: 200px;">Middle</div> <!-- dummy width -->
        <div style="float: left; position: relative; width: 200px;">Right</div> <!-- dummy width -->
      </div>
    

    Also, you'll need to specify the width for each of these divs.

    What is your reasoning behind floating them to the right?

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