调整大小时将侧导航栏转入顶栏

时间:2018-06-11 23:59:28

标签: twitter-bootstrap resize navbar

嘿大家我有一个网站可以解释我想要完成的任务,我们将非常感谢您寻找优秀教程的任何帮助。

如果你去这里并调整页面大小,你会看到侧栏变成顶栏。我怎么能这样做?

http://portlanddecorating.co.uk/

我还没有找到任何教程。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

因为一个视觉例子比言语更响亮......

以下是创建垂直导航栏的一种方法。请注意,媒体查询需要根据导航栏标记navbar-expand-<size>中使用的<nav class="navbar navbar-expand-sm ...类进行调整

有关详情,请参阅Bootstrap 4 Responsive breaks

&#13;
&#13;
@media only screen and (min-width: 576px) {
  .vertiNav {
    width: 100px;
  }
  .vertiNav nav.navbar {
    flex-direction: column !important;
  }
}

@media only screen and (max-width: 576px) {
  .vertiNav {
    width: 100%;
  }
  .vertiNav nav.navbar {
    flex-direction: row !important;
  }
}
&#13;
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>

<div class="vertiNav">
  <nav class="navbar navbar-expand-sm 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 flex-column">
        <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>
</div>
&#13;
&#13;
&#13;