如何在 bulma navbar-item 中居中图标和文本

how to center icon and text in bulma navbar-item

我开始使用 Bulma 和 Buefy 框架,但遇到了这个问题。
我正在尝试复制 google 应用程序菜单,我创建了一个导航栏项目 div 并将以下代码放入其中:

<div class="columns">
    <div class="column">
        <a>
            <b-icon
                icon="cloud-outline">
            </b-icon>
            <span>function 1</span>
        </a>
    </div>
    <div class="column">
        <b-icon
            icon="compass">
        </b-icon>
        Function 2
    </div>
    <div class="column">
        <b-icon
            icon="scatter-plot">
        </b-icon>
        Function 3
    </div>
</div>

输出是:

我想要达到的效果如下:

如何使图标居中并将文本移到新行?

您可以使用 css flex 来做到这一点。通过使用附加键:

.columns {
  display: flex;
  justify-content: space-evenly;
}

.column {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.columns {
  display: flex;
  justify-content: space-evenly;
}

.column {
  display: flex;
  flex-direction: column;
  align-items: center;
}
<div class="columns">
  <div class="column">
    <span>icon</span>
    <span>function 1</span>
  </div>
  <div class="column">
    <span>icon</span> Function 2
  </div>
  <div class="column">
    <span>icon</span> Function 3
  </div>
</div>

您可以使用 flexbox 来设置链接的样式:

.custom-nav a {
  display: flex;
  flex-flow: column nowrap;
  align-items: center;
  padding: 1em;
  background-color: rgba(0, 0, 0, 0.1);
}

.custom-nav i {
  font-size: 3rem;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.1/css/bulma.min.css" integrity="sha256-1nEaE91OpXJD7M6W5uSiqxhdmrY+lOOTHC1iUxU9Pds=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js" integrity="sha256-KzZiKy0DWYsnwMF+X1DvQngQ2/FxF7MF3Ff72XcpuPs=" crossorigin="anonymous"></script>

<div class="columns custom-nav">

  <div class="column">
    <a href="#">
      <i class="fas fa-box-tissue fa-2x"></i>
      <span>function 1</span>
    </a>
  </div>

  <div class="column">
    <a href="#">
      <i class="fas fa-handshake-slash fa-2x"></i>
      <span>function 2</span>
    </a>
  </div>

  <div class="column">
    <a href="#">
      <i class="fas fa-head-side-mask fa-2x"></i>
      <span>function 3</span>
    </a>
  </div>

  <div class="column">
    <a href="#">
      <i class="fas fa-shield-virus fa-2x"></i>
      <span>function 3</span>
    </a>
  </div>

</div>