我有一个标准的bootstrap导航栏,在移动设备上崩溃。在下面的代码中,供您参考:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Menu with dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Submenu voice 1</a></li>
<li><a href="#">Submenu voice 2</a></li>
<li><a href="#">Submenu voice 3</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
我想在点击手机上的汉堡菜单后,直接获取3 <li>
“子菜单语音x”并隐藏父<li>
(class =“dropdown”)。
我怎样才能达到这个效果?谢谢
答案 0 :(得分:1)
您可以使用CSS:
@media (max-width: 767px) {
.navbar-nav .dropdown-menu {
display: block;
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.dropdown-toggle {
display: none !important;
}
.navbar-inverse .navbar-nav .dropdown-menu > li > a {
color: #9d9d9d;
}
}
答案 1 :(得分:0)
我必须将以下内容添加到.navbar-nav .dropdown-menu中才能使其正常工作。
opacity:1;
visibility: visible;
答案 2 :(得分:0)
尝试下面的代码。
<nav class="main-menu navbar-expand-md">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent1" aria-controls="navbarSupportedContent1" aria-expanded="false" aria-label="Toggle navigation">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-collapse collapse clearfix" id="navbarSupportedContent1">
<ul class="navigation clearfix">
<li class="current dropdown"><a routerLink="/">Home</a>
</li>
<li class="dropdown"><a href="javascript:void(0)">About</a>
<ul class="dropdown-menu">
<li><a href="/company-overview">Company Overview</a></li>
<li><a href="/vision-mission">Vision Mission</a></li>
<li><a href="/ethics-corevalues">Ethics & Core Values</a></li>
</ul>
</li>
</ul>
</div>
</nav>
.dropdown:hover > .dropdown-menu{
display: block;
}