How to have two items on opposite sides on the same line

前端 未结 3 1767
一生所求
一生所求 2020-12-03 14:12

I\'m trying to get two different pieces of text on opposite ends of the \"page\" so to speak for a mobile app.

I would like it to look like this:

|--         


        
相关标签:
3条回答
  • 2020-12-03 14:43

    Johannes Flexbox approach is probably the best way, but without using that, or float as you requested, you could do something like this:

    <div id="HASH" class="blue-msg">
      <div id="left">
        <span id="time-HASH" class="smalltext">9 months 2 weeks ago</span>
      </div>
      <div id="right">
        <span class="ios-circle">MESSAGE HERE</span>
      </div>
    </div>
    

    And then:

    #HASH {
      width: 100%;
    }
    
    #HASH div {
      width: 49%;
      display: inline-block;
    }
    
    #right {
      text-align: right;
    }
    

    https://jsfiddle.net/ak7zxz84/

    Again, I'd go with Flexbox, but this is just an alternate solution.

    0 讨论(0)
  • 2020-12-03 15:00

    Use flexbox, like this

    #HASH {
      display: flex;
      justify-content: space-between;
    }
    

    P.S.: If the "MESSAGE HERE" content is supposed to expand across multiple lines, I would put it in a div (instead of span) and restrict its width to 50% (adjust value as you like).

    #HASH {
      display: flex;
      justify-content: space-between;
    }
    <div id="HASH" class="blue-msg">
    <span id="time-HASH" class="smalltext">9 months 2 weeks ago</span>
    <span class="ios-circle">MESSAGE HERE</span>
    </div>

    0 讨论(0)
  • 2020-12-03 15:06

    If you want it fixed to the bottom (or another) area of the screen, why not use fixed positioning, such as:

    #time-HASH {
    position: fixed;
    bottom: 0;
    left: 0;
    }
    
    .ios-circle {
    position: fixed;
    bottom: 0;
    right: 0;
    display: inline-block; //if you need this
    
    }
    
    0 讨论(0)
提交回复
热议问题