如何修复中心的bootstrap导航切换按钮

问题描述 投票:1回答:2

我在bootstrap 4导航中遇到问题,我想设置左侧Logo /品牌和中心导航按钮和右侧登录/我的帐户按钮,我试图解决这个问题,但是当我点击移动设备上的导航按钮时它突然向右移动,请看代码播放http://codeply.com/go/8FOVzFRkfM

<nav class="navbar navbar-expand-md navbar-light" >
    <div class="container"> <a class="navbar-brand text-primary" href="#">
        <i class="fa d-inline fa-lg fa-stop-circle"></i>
        <b> BRAND</b>
      </a> <button class="navbar-toggler navbar-toggler-right border-0" type="button" data-toggle="collapse" data-target="#navbar4">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbar4">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item bg-white border-success"> <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" href="#">About</a> </li>
          <li class="nav-item"> <a class="nav-link" href="#">FAQ</a> </li>
        </ul> 
      </div>
      <span> <a class="btn navbar-btn ml-md-2 btn-light bg-info">My Account</a></span>
    </div>

  </nav>
css html5 bootstrap-4 navbar
2个回答
0
投票

您只需要在order-md-0 order-last上使用navbarcollapse,使其位于移动屏幕宽度的最后位置(当Navbar折叠时)...

 <div class="collapse navbar-collapse order-md-0 order-last" id="navbar4">
    <ul class="navbar-nav ml-auto">
      <li class="nav-item bg-white border-success"> <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" href="#">About</a> </li>
      <li class="nav-item"> <a class="nav-link" href="#">FAQ</a> </li>
    </ul> 
 </div>

https://www.codeply.com/go/KkYoATqtFy


相关:Bootstrap NavBar with left, center or right aligned items


0
投票

container内部的navbar是一个flexjustify-content: space-between,因此最初隐藏的navbar-collpase显示在切换下面被推到下面。

解决方案:将navbar-collpase定位为导航栏的绝对位置将解决问题。

例:

@media only screen and (max-width: 600px) {
  .navbar-collapse{
        position: absolute;
        width: 100%;
        top: 56px; /*height of navbar in mobile*/
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.