Bootstrap 3.3从嵌套链接隐藏导航栏

时间:2019-03-03 02:13:10

标签: jquery css twitter-bootstrap

我知道这是一个常见的问题,但是我发烧了,使我无法正常工作使我付出了代价:

<nav class="navbar navbar-default navbar-fixed-top small-screen">
<div class="container-fluid">
  <div class="navbar-header" style="border-bottom: 1px solid #dedede; width: 100%">
    <a class="navbar-brand top-logo"><img src="img/any.jpg" alt="MRT"/></a>
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-right2">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>
  <div id="menor" class="collapse navbar-right2">
    <ul>
      <li><div class="active">Index</div></li>
      <li><div class="inactive"><a 01.php">One</a></div></li>
      <li><div class="inactive"><a href="02.php">Two</a></div></li>
      <li><div class="inactive"><a href="03.php">Three</a></div></li>
      <li><div class="inactive"><a href="#contact">CONTACT</a></div></li>
    </ul>
  </div>


我必须将联系表单添加到页脚中,所以现在我需要在单击“联系”后隐藏导航。

我确实尝试过在Stackoverflow中找到的几种解决方案,但没有一个起作用。

任何提示将不胜感激。

1 个答案:

答案 0 :(得分:1)

如果您希望“联系人”链接的行为与切换导航按钮的行为完全相同,只需在该联系人链接中添加data-toggle="collapse" data-target=".navbar-right2" ...

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" 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.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>


<nav class="navbar navbar-default navbar-fixed-top small-screen">
<div class="container-fluid">
  <div class="navbar-header" style="border-bottom: 1px solid #dedede; width: 100%">
    <a class="navbar-brand top-logo"><img src="img/any.jpg" alt="MRT"/></a>
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-right2">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>
  <div id="menor" class="collapse navbar-right2">
    <ul>
      <li><div class="active">Index</div></li>
      <li><div class="inactive"><a href="01.php">One</a></div></li>
      <li><div class="inactive"><a href="02.php">Two</a></div></li>
      <li><div class="inactive"><a href="03.php">Three</a></div></li>
      <li><div class="inactive"><a href="#contact" data-toggle="collapse" data-target=".navbar-right2">CONTACT</a></div></li>
    </ul>
  </div>