0

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

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

<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 来做到这一点吗?

此问题类似,但使用 OnsenUI 和 Monaca(对 ios 和 android 都很好)

4

2 回答 2

1
<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;
}
于 2017-09-14T10:58:23.450 回答
0
// 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/

于 2017-09-14T10:59:32.547 回答