Search code examples
csstwitter-bootstrapcenteronsen-ui2

Center a button between two others in OnsenUI


How do I center a button between two other buttons in a toolbar?

Here's my code and resulting screenshot

<div id="toptoolbar">
  <button class="toolbar-button">
    <i class="fa fa-comments" style="font-size:17px"></i>
  </button>

  <button class="toolbar-button">
    My title
    <!-- text-purple center-block doesn't work -->
  </button>

  <button class="toolbar-button pull-right">
    <i class="fa fa-ellipsis-v" style="font-size:17px"></i>
  </button>
</div>

enter image description here

I'm using OnsenUI (and will be using VUE with it) so is there a class I can simply add from bootstrap or any other framework included with OnsenUI?

Or can I use some custom CSS to do this?

Similar to this question but with OnsenUI and Monaca (so good for both ios and android)


Solution

  • <div id="toptoolbar">
      <button class="toolbar-button">
        <i class="fa fa-comments" style="font-size:17px"></i>
      </button>
      <span class="stretcher"></span>
      <button class="toolbar-button">
        My title
        <!-- text-purple center-block doesn't work -->
      </button>
      <span class="stretcher"></span>
      <button class="toolbar-button pull-right">
        <i class="fa fa-ellipsis-v" style="font-size:17px"></i>
      </button>
    </div>
    

    CSS:

    #toptoolbar {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .stretcher {
       flex: 1;
    }