Bootstrap 3下拉导航无法保持专注

时间:2013-11-07 19:48:45

标签: css twitter-bootstrap focus twitter-bootstrap-3 nav

我有一个Bootstrap导航:

<nav class="navbar navbar-default" role="navigation"> 
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
  <a class="navbar-brand" href="#"><img src="img/logo.png"></a> </div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  <ul class="nav navbar-nav navbar-right">
    <li class="active"><a href="#">Home</a></li>
    <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Neuigkeiten <b class="caret"></b></a>
    <ul class="dropdown-menu">
      <li><a href="#">News</a></li>
      <li><a href="#">Events</a></li>
      <li><a href="#">Galerie</a></li>
    </ul>
  </li>
    <li><a href="#">Fahrzeuge</a></li>
    <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Ausbildung <b class="caret"></b></a>
    <ul class="dropdown-menu">
      <li><a href="#">Allgemein</a></li>
      <li class="divider"></li>
      <li><a href="#">Versehrten</a></li>
      <li><a href="#">Fremdsprachig</a></li>
      <li><a href="#">Ferien</a></li>
      <li class="divider"></li>
      <li><a href="#">Seminare</a></li>
    </ul>
  </li>
  <li><a href="#">LKW</a></li>  
  </ul>
  <!--<ul class="nav navbar-nav navbar-right">
  <li><a href="#">Link</a></li>
  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
    <ul class="dropdown-menu">
      <li><a href="#">Action</a></li>
      <li><a href="#">Another action</a></li>
      <li><a href="#">Something else here</a></li>
      <li class="divider"></li>
      <li><a href="#">Separated link</a></li>
    </ul>
  </li>
</ul>--> 
</div>
<!-- /.navbar-collapse --> 

并做了一些悬停效果(我更改了背景颜色)。现在我希望下拉菜单也出现在悬停状态。所以我补充说:

ul.nav li.dropdown:hover ul.dropdown-menu{
display: block;
margin-top:-1px;
}

但是现在如果鼠标离开主菜单项以便在现在打开的下拉菜单中单击某些内容,则它不再具有更改的背景颜色...(因为它不再聚焦了?!?)

但即使鼠标在相应的下拉菜单中导航,我还必须做什么才能使主菜单项保持聚焦(保持悬停背景颜色)?

2 个答案:

答案 0 :(得分:0)

当下拉菜单悬停时,您还需要修改.dropdown-toggle。添加以下CSS

ul.nav li.dropdown:hover .dropdown-toggle {
   color: #555;
   background-color: #e7e7e7;
}

答案 1 :(得分:0)

更好的方法是使用这样的jQuery:

$('.navbar-toggle').click(function() {
    if (!$(this).hasClass('collapsed')) {
        $(this).blur();
    };
});