可折叠按钮菜单如何显示在屏幕右侧而不是使用Bootstrap-4

时间:2018-03-07 05:15:13

标签: html css flexbox bootstrap-4 navbar

嗨,我是网络开发的新手,还在学习。我的导航栏出现问题,导致从屏幕左侧导航栏上的flexbox按钮弹出的collapsable菜单,到目前为止我没有尝试过任何操作移动。

    <nav class="navbar sticky-top navbar-expand-md navbar-dark bg-dark">   
  <a class "navbar-brand justify-content-start" href="#">
      <img src="https://pbs.twimg.com/profile_images/91427004/brule_400x400.jpg" alt="Logo" style="width: 60px;">
    </a>
    <div class="d-flex w-80 ml-auto">
      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#collapsingNavbar">
            <span class="navbar-toggler-icon"></span>
        </button>     
    </div>
    <div class="navbar-collapse collapse" id="collapsingNavbar">
      <ul class="navbar-nav navbar-right ml-auto">

        <li class="nav-item active expandMenu">
          <a class="nav-link" href="#">Portfolio</a>
        </li>
        <li class="nav-item active expandMenu">
          <a class="nav-link" href="#">Portfolio</a>
        </li>
        <li class="nav-item active expandMenu">
          <a class="nav-link" href="#">Contact</a>
        </li>
      </ul>
    </div>
  </nav>
代码下面的

是CSS:

nav {
  width: 100%;
  height: 70px;
  font-size: 175%;
}

.expandMenu {

  background: rgb(52, 58, 64);
  width: 50%;
  margin-top: -5px;
  text-align: center;

}

1 个答案:

答案 0 :(得分:0)

将班级navbar-right的宽度设为50%,并从width移除.expandMenu 50%

&#13;
&#13;
nav {
  width: 100%;
  height: 70px;
  font-size: 175%;
}

.expandMenu {
  background: rgb(52, 58, 64);
  margin-top: -5px;
  margin-left 100%;
  text-align: center;
}

.navbar-right {
  width: 50%;
}
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<nav class="navbar sticky-top navbar-expand-md navbar-dark bg-dark">
  <a class "navbar-brand justify-content-start" href="#">
    <img src="https://pbs.twimg.com/profile_images/91427004/brule_400x400.jpg" alt="Logo" style="width: 60px;">
  </a>
  <div class="d-flex w-80 ml-auto">
    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#collapsingNavbar">
            <span class="navbar-toggler-icon"></span>
        </button>
  </div>
  <div class="navbar-collapse collapse" id="collapsingNavbar">
    <ul class="navbar-nav navbar-right ml-auto">

      <li class="nav-item active expandMenu">
        <a class="nav-link" href="#">Portfolio</a>
      </li>
      <li class="nav-item active expandMenu">
        <a class="nav-link" href="#">Portfolio</a>
      </li>
      <li class="nav-item active expandMenu">
        <a class="nav-link" href="#">Contact</a>
      </li>
    </ul>
  </div>
</nav>
&#13;
&#13;
&#13;