我的引导导航栏工作正常,但是如果我在开发人员工具中切换到电话视图并单击“展开”按钮,则它不会展开。
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Storyfactory</a>
<button class="navbar-toggler collapsed bg-primary" type="button" data-toggle="#hanshuber" data-target="#navbar" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="hanshuber">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>
</ul>
<a href="/user/2" class="mr-3"><i class="fas fa-user"></i></a>
<a href="http://localhost:8000/logout"><i class="fas fa-sign-out-alt"></i></a>
</div>
</nav>
答案 0 :(得分:1)
您的toggle
和target
数据属性不正确。
data-toggle="collapse" data-target="#hanshuber"
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Storyfactory</a>
<button class="navbar-toggler collapsed bg-primary" type="button" data-toggle="collapse" data-target="#hanshuber" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="hanshuber">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>
</ul>
<a href="/user/2" class="mr-3"><i class="fas fa-user"></i></a>
<a href="#"><i class="fas fa-sign-out-alt"></i></a>
</div>
</nav>