导航栏中的div href

时间:2018-10-01 16:20:49

标签: javascript html css bootstrap-4

我正在使用引导程序中的模板。 This is the navigation bar,您可以在其中看到“关于”部分。就我而言,里面有一个引导按钮:

<button type="button" class="btn btn-light">Light</button>

按下按钮后,导航栏有望通过向下滑动以显示“关于”部分来打开。

我已经使用已知的CSS完成了所有工作,例如使用href。我认为这与引导程序的Javascript部分,.onclick函数或类似内容有关。

请帮助。

1 个答案:

答案 0 :(得分:0)

对于包含导航栏的about部分的div,请给其class="collapse"和一个ID,例如id="navbarHeader"

对于按钮添加,data-toggle="collapse" data-target="#navbarHeader"

确保已从引导程序(以及样式)导入了javascript导入:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> 
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

查看此stackblitz以获得参考(您链接到的相册页面的副本)。

    <header>
      <div class="collapse bg-dark" id="navbarHeader">
        <div class="container" style="height:200px">
          <!-- add your hidden content (expands to the height of this content-->
          <!-- if no content, then nothing to expand, i added style="height:200px", but this can be removed -->
        </div>
      </div>
      <div class="navbar navbar-dark bg-dark">
        <div class="container">
          <a href="#" class="navbar-brand d-flex align-items-center">
            <!-- your brand text/image -->
          </a>
          <!-- The menu button -->
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHeader">
            <span class="navbar-toggler-icon"></span>
          </button>
        </div>
      </div>
    </header>