我正在尝试使nav
菜单在移动设备上折叠,而不在台式机上折叠。
添加data-toggle="collapse" data-target="#navbarResponsive"
似乎可以,但是在桌面设备上单击nav
项时它们也会折叠。
<div class="py-0 px-3 fixed-top">
<nav class="navbar container navbar-transparent navbar-padded navbar-expand-md">
<a class="navbar-brand" href="#">
Logo
</a>
<button
class="navbar-toggler navbar-toggler-right d-md-none"
type="button"
data-toggle="collapse"
data-target="#navbarResponsive"
aria-controls="navbarResponsive"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-uppercase" id="navbarResponsive">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item" data-toggle="collapse" data-target="#navbarResponsive">
<a class="nav-link"href="#link1">link1</a>
</li>
<li class="nav-item" data-toggle="collapse" data-target="#navbarResponsive">
<a class="nav-link" href="#link2">link2</a>
</li>
</ul>
</div>
</nav>
</div>
答案 0 :(得分:0)
将数据目标更改为移动折叠版本:.navbar-collapse.show
<li class="nav-item" data-toggle="collapse" data-target=".navbar-collapse.show">
<a class="nav-link" href="#link1">link1</a>
</li>
演示:https://www.codeply.com/go/qBh0qJYekK