2014-10-21 161 views
2

我想通過使用引導來創建導航欄,但是當我將活動類重定向到下拉菜單時,所有子菜單都會接收活動類。我只希望工程部分使用主動類引導下拉菜單活動類

<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

既然不能看到CSS代碼...你需要添加和ul>之間li

li > ul 
2

您需要使用.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>