我正在尝试使用引导程序创建导航栏但是当我将活动类重定向到下拉菜单时,所有子菜单都会接收活动类。我只希望Project部分使用活动类
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target="#example-navbar-collapse">
<span class="sr-only"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="example-navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">About</a></li>
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Project <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="project.html">AAAA</a></li>
<li><a href="#">BBB</a></li>
<li><a href="#">CCC</a></li>
<li><a href="#">DDD</a></li>
</ul>
</li>
<li><a href="team.html">Team</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
</nav>
答案 0 :(得分:1)
您需要使用.navbar-default .navbar-nav>.active>a { //styles here for active li }
仅定位有效<li>
,如下所示:
.dropdown-menu {
display: block !important;
}
.navbar-default .navbar-nav>.active>a {
color: blue !important;
background: red !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-navbar-collapse">
<span class="sr-only"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="example-navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">About</a>
</li>
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Project <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="project.html">AAAA</a>
</li>
<li><a href="#">BBB</a>
</li>
<li><a href="#">CCC</a>
</li>
<li><a href="#">DDD</a>
</li>
</ul>
</li>
<li><a href="team.html">Team</a>
</li>
<li><a href="contact.html">Contact</a>
</li>
</ul>
</div>
</nav>
答案 1 :(得分:0)
由于我看不到css代码...您需要在>
和li
之间添加ul
li > ul