我是引导的菜鸟。
在简单的引导导航栏中,我希望它在用户单击导航项时也折叠。 所以我做了下面给出的更改。
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="nav navbar-brand">RAHUL SONI</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="#" data-toggle="collapse" data-target="#navbar-collapse-1">About</a></li>
<li><a href="#" data-toggle="collapse" data-target="#navbar-collapse-1">Survey</a></li>
</ul>
</div>
</div>
</nav>
它按照我的意愿工作。但是数据切换="折叠" 数据目标="#navbar-折叠-1" 当我的导航栏处于正常状态时,它也会起作用。
我的代码片段
请提出建议。
现在看到您的数据没有切换您想要的:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- row 1 -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="http://www.abiworld.org" class="nav navbar-brand">RAHUL SONI</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="#" data-target="#navbar-collapse-1">About</a></li>
<li><a href="#" data-target="#navbar-collapse-1">Survey</a></li>
</ul>
</div>
</div>
</nav>