【问题标题】:href a div inside a navbarhref 导航栏中的 div
【发布时间】:2018-10-02 04:11:37
【问题描述】:

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

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

按下按钮后,导航栏应该会通过向下滑动来打开并显示 about 部分。

我已经用 CSS 完成了所有我知道的事情,比如使用 href。我认为这与引导程序的 Javascript 部分、.onclick 函数或类似的东西有关。

请帮忙。

【问题讨论】:

  • 发布您尝试过的代码。

标签: javascript html css bootstrap-4


【解决方案1】:

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

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

确保您已经从 bootstrap 导入了 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>

【讨论】:

  • 非常感谢。这太容易了,我真的花了 1 天时间在谷歌上搜索它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-14
  • 1970-01-01
  • 1970-01-01
  • 2012-10-24
  • 2013-03-22
  • 2015-01-24
  • 1970-01-01
相关资源
最近更新 更多