移动菜单下拉问题

时间:2017-03-14 15:31:37

标签: html css twitter-bootstrap-3

我的引导程序移动菜单需要可点击的子菜单。顶部菜单是可点击的,但无论我尝试什么,子菜单都会悬停。我添加了数据切换,但这没有帮助。我在这里想念的是什么? 这是我的代码:

http://codepen.io/iamgonge/pen/yMoMpV

HTML:

<nav class="navbar navbar-inverse" role="navigation">
   <div class="container-fluid">
      <!-- header -->
      <div class="navbar-header">
         <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#multi-level-dropdown">
         <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="index.html">LOGO</a>
      </div>
      <!-- menus -->
      <div class="collapse navbar-collapse" id="multi-level-dropdown">
         <ul class="nav navbar-nav">
         <li><a href="#">Software</a></li>
         <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">hardware<b class="caret"></b></a>
            <ul class="dropdown-menu">

            <li class="dropdown-submenu">
               <a href="#" class="dropdown-toggle" data-toggle="dropdown">submenu</a>
               <ul class="dropdown-menu">
               <li><a href="#">stuff</a></li>
               <li><a href="#">stuff</a></li>

               </ul>
            </li>
            </ul>
         </li>
         <li><a href="#">accessories</a></li>
         <li><a href="#">electronics</a></li>
         </ul>
      </div>
   </div>
</nav>

的CSS:

.nav .navbar-nav{color: #fff;}

.navbar{background-color:#4F96BA;
}.dropdown-submenu {
    position: relative;
}

.dropdown-submenu > .dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -5px;
    margin-left: -1px;
    -webkit-border-radius: 0 6px 6px 6px;
    -moz-border-radius: 0 6px 6px;
    border-radius: 0 6px 6px 6px;
}

.dropdown-submenu:hover > .dropdown-menu {
    display: block;
}

.dropdown-submenu > a:after {
    display: block;
    content: " ";
    float: right;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    border-width: 5px 0 5px 5px;
    border-left-color: #ccc;
    margin-top: 5px;
    margin-right: -10px;
}

.dropdown-submenu:hover > a:after {
    border-left-color: #333;
}

.dropdown-submenu.pull-left {
    float: none;
}

.dropdown-submenu.pull-left > .dropdown-menu {
    left: -100%;
    margin-left: 10px;
    -webkit-border-radius: 6px 0 6px 6px;
    -moz-border-radius: 6px 0 6px 6px;
    border-radius: 6px 0 6px 6px;
}

.navbar-inverse .navbar-nav>li>a {    
    color: #fff;
  text-transform: uppercase;
}

1 个答案:

答案 0 :(得分:1)

Jquery的

(function($){
        $(document).ready(function(){
            $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
                event.preventDefault(); 
                event.stopPropagation(); 
                $(this).parent().siblings().removeClass('open');
                $(this).parent().toggleClass('open');
            });
        });
    })(jQuery);

HTML

<nav class="navbar navbar-inverse navbar-static-top marginBottom-0" role="navigation">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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="#" target="_blank">NewWindow</a>
    </div>

    <div class="collapse navbar-collapse" id="navbar-collapse-1">
        <ul class="nav navbar-nav">
            <li class="active"><a href="#">Active Link</a></li>
            <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="#">Dropdown Link 1</a></li>
                    <li><a href="#">Dropdown Link 2</a></li>
                    <li><a href="#">Dropdown Link 3</a></li>
                    <li class="divider"></li>
                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Link 4</a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Dropdown Submenu Link 4.1</a></li>
                            <li><a href="#">Dropdown Submenu Link 4.2</a></li>
                            <li><a href="#">Dropdown Submenu Link 4.3</a></li>
                            <li><a href="#">Dropdown Submenu Link 4.4</a></li>
                        </ul>
                    </li>
                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Link 5</a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Dropdown Submenu Link 5.1</a></li>
                            <li><a href="#">Dropdown Submenu Link 5.2</a></li>
                            <li><a href="#">Dropdown Submenu Link 5.3</a></li>
                            <li class="divider"></li>
                            <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Submenu Link 5.4</a>
                                <ul class="dropdown-menu">
                                    <li><a href="#">Dropdown Submenu Link 5.4.1</a></li>
                                    <li><a href="#">Dropdown Submenu Link 5.4.2</a></li>
                                    <li class="divider"></li>
                                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Submenu Link 5.4.3</a>
                                        <ul class="dropdown-menu">
                                            <li><a href="#">Dropdown Submenu Link 5.4.3.1</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.3.2</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.3.3</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.3.4</a></li>
                                        </ul>
                                    </li>
                                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Submenu Link 5.4.4</a>
                                        <ul class="dropdown-menu">
                                            <li><a href="#">Dropdown Submenu Link 5.4.4.1</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.4.2</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.4.3</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.4.4</a></li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </li>
                </ul>
            </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="#">Dropdown Link 1</a></li>
                    <li><a href="#">Dropdown Link 2</a></li>
                    <li><a href="#">Dropdown Link 3</a></li>
                    <li class="divider"></li>
                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Link 4</a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Dropdown Submenu Link 4.1</a></li>
                            <li><a href="#">Dropdown Submenu Link 4.2</a></li>
                            <li><a href="#">Dropdown Submenu Link 4.3</a></li>
                            <li><a href="#">Dropdown Submenu Link 4.4</a></li>
                        </ul>
                    </li>
                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Link 5</a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Dropdown Submenu Link 5.1</a></li>
                            <li><a href="#">Dropdown Submenu Link 5.2</a></li>
                            <li><a href="#">Dropdown Submenu Link 5.3</a></li>
                            <li class="divider"></li>
                            <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Submenu Link 5.4</a>
                                <ul class="dropdown-menu">
                                    <li><a href="#">Dropdown Submenu Link 5.4.1</a></li>
                                    <li><a href="#">Dropdown Submenu Link 5.4.2</a></li>
                                    <li class="divider"></li>
                                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Submenu Link 5.4.3</a>
                                        <ul class="dropdown-menu">
                                            <li><a href="#">Dropdown Submenu Link 5.4.3.1</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.3.2</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.3.3</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.3.4</a></li>
                                        </ul>
                                    </li>
                                    <li class="dropdown dropdown-submenu"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown Submenu Link 5.4.4</a>
                                        <ul class="dropdown-menu">
                                            <li><a href="#">Dropdown Submenu Link 5.4.4.1</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.4.2</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.4.3</a></li>
                                            <li><a href="#">Dropdown Submenu Link 5.4.4.4</a></li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </div><!-- /.navbar-collapse -->

代码:http://www.bootply.com/97919