Bootstrap 导航栏汉堡包图标未垂直对齐

Bootstrap navbar hamburger icon does not align vertically

我使用 Fluent kit 和 bootstrap 4.1.2。

来自 navbar docs(我想要这个,因为切换器会在打开/关闭时更改其图标)我确实采用了第二个示例,来自 #position 部分。然而,汉堡不是垂直居中的。我该如何解决?

带有错误汉堡包的导航栏:

我尝试删除 padding 但没有用,我卡住了。

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/nespero/fluent-kit@1.3.0/js/fluent-kit.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/gh/nespero/fluent-kit@1.2.0/css/fluent-kit.min.css" rel="stylesheet"/>

<nav class="navbar navbar-dark bg-dark py-2">
  <strong class="navbar-text">
    Navbar position example
  </strong>
  <button class="btn mi navbar-toggler  shadow-none mt-0" type="button" data-toggle="collapse" data-target="#navbar-position" aria-controls="navbar-position" aria-expanded="false" aria-label="Toggle navigation">
    <span class="sr-only">Toggle navbar submenu</span>
  </button>
  <div class="collapse navbar-collapse" id="navbar-position">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Features</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Pricing</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
  </div>
</nav>

<button>

中删除 .btn class

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/nespero/fluent-kit@1.3.0/js/fluent-kit.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/gh/nespero/fluent-kit@1.2.0/css/fluent-kit.min.css" rel="stylesheet"/>

<nav class="navbar navbar-dark bg-dark py-2">
  <strong class="navbar-text">
    Navbar position example
  </strong>
  <button class="mi navbar-toggler  shadow-none mt-0" type="button" data-toggle="collapse" data-target="#navbar-position" aria-controls="navbar-position" aria-expanded="false" aria-label="Toggle navigation">
    <span class="sr-only">Toggle navbar submenu</span>
  </button>
  <div class="collapse navbar-collapse" id="navbar-position">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Features</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Pricing</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
  </div>
</nav>

将此 css 添加到您的 css 文件中。

.navbar .navbar-toggler {
    padding: .5rem .75rem;
}

在您的 css 文件中添加此 css 代码:

nav.navbar .navbar-toggler {
    line-height: 10px;
    padding: 0;
}

你也可以用transform:translateY对齐

.navbar .navbar-toggler {
   transform: translateY(-17%);
 }