【问题标题】:Center a button between two others in OnsenUI在 OnsenUI 中将其他两个按钮居中
【发布时间】:2018-02-23 07:24:34
【问题描述】:

如何在工具栏中的其他两个按钮之间居中放置一个按钮?

这是我的代码和生成的屏幕截图

<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>

我正在使用 OnsenUI(并将与它一起使用 VUE)所以我可以从引导程序或 OnsenUI 包含的任何其他框架中简单地添加一个类吗?

或者我可以使用一些自定义 CSS 来执行此操作吗?

类似to this question,但使用 OnsenUI 和 Monaca(对 ios 和 android 都很好)

【问题讨论】:

    标签: css twitter-bootstrap center onsen-ui2


    【解决方案1】:
    // HTML
    
    <div id="toptoolbar">
      <button class="toolbar-button">
        <i class="fa fa-comments" style="font-size:17px"></i>
      </button>
    
      <button class="toolbar-button title">
        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>
    
    //CSS
    
    .toolbar-button.title{
      position: absolute;
      left: 49%;
    }
    

    这只是一个简单的 CSS 解决方案。 更新小提琴http://jsfiddle.net/JfGVE/2459/

    【讨论】:

      【解决方案2】:
      <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;
      }
      

      【讨论】:

      • 他只希望第二个按钮位于中间。如果我错了,请纠正。
      • 我的代码将使 msg 图标在左侧,我的标题在中心,3 点图标在右侧
      • : Oopppsss 抱歉在错误的地方更新了你的代码。它有效.. 如果你给了一个小提琴,我会喜欢的。复制粘贴很痛:)
      猜你喜欢
      • 1970-01-01
      • 2021-07-20
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 2013-08-07
      相关资源
      最近更新 更多