如何在Bootstrap 4中垂直对齐navbar-toggler?

时间:2017-07-24 17:37:13

标签: twitter-bootstrap navbar vertical-alignment

我无法在导航栏中对齐toggler。使用Bootstrap 4. Align-items-center没有帮助。

代码:

<nav class="navbar navbar-toggleable-sm py-3">

    <button class="navbar-toggler navbar-toggler-right collapsed" type="button" data-toggle="collapse" data-target="#navbar">
        <span class="icon-bar"> </span>
        <span class="icon-bar"> </span>
        <span class="icon-bar"> </span>
    </button>

    <a class="navbar-brand d-inline-flex align-items-center" href="#">
        <img src="img/brand-logo.png" class="brand__logo img-fluid mr-2" alt="brand-logo">
        Logo
    </a>

    <div class="collapse navbar-collapse justify-content-end" id="navbar">
        <ul class="navbar-nav">
            <li class="nav-item active">
                <a class="nav-link" href="#">Info</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Login</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Sign Up</a>
            </li>
        </ul>
    </div>
</nav>

结果如下:example

2 个答案:

答案 0 :(得分:1)

我希望这会对您有所帮助。

@media (max-width: 768px){
    .navbar {
           display:block;
           text-align:center;
    }
}

答案 1 :(得分:0)

如果直接使用bootstrap的导航栏示例代码,则无需管理它,它会自动处理各种屏幕尺寸上的调整

下面是代码:-

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
    <div class="navbar-nav">
      <a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="nav-item nav-link" href="#">Features</a>
      <a class="nav-item nav-link" href="#">Pricing</a>
      <a class="nav-item nav-link disabled" href="#">Disabled</a>
    </div>
  </div>
</nav>

使用bootstrap 4.0.0 这是参考链接

https://getbootstrap.com/docs/4.0/components/navbar/