bootstrap 3个多个导航项目一次打开

问题描述 投票:1回答:1

我正在尝试使用bootstrap 3进行多个导航工作。目前我遇到了第一个菜单点击的问题(即左边的汉堡菜单 - 参见附件图片)打开所有菜单项。下一次单击将关闭所有项目,然后后续单击按预期运行,一次打开一个菜单项。

<div class="navbar navbar-inverse navbar-fixed-top" id="#navGroup">
    <div class="container">
        <div class="row" id="navGroup">
            <div class="navbar-header col-xs-4">
                <button type="button" class="navbar-toggle navbar-left" data-toggle="collapse" data-target=".burger-collapse" data-parent="#navGroup">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                </button>
            </div>
            <div class="navbar-header col-xs-4">
                <a class="navbar-brand" href='@Url.Action("Home", "Home")'>
                <i class="glyphicon glyphicon-home logo-glyph"></i>
                </a>
            </div>
            <div class="navbar-header col-xs-4">
                <button class="navbar-toggle glyphicon air-listing-nav glyphicon-user" data-toggle="collapse" data-target=".profile-collapse" data-parent="#navGroup"></button>
                <button class="navbar-toggle glyphicon air-listing-nav glyphicon-bell" data-toggle="collapse" data-target=".notifications-collapse" data-parent="#navGroup"></button>
                <button class="navbar-toggle glyphicon air-listing-nav glyphicon-question-sign" data-toggle="collapse" data-target=".help-collapse" data-parent="#navGroup"></button>
            </div>
        </div>
        <div class="navbar-collapse collapse burger-collapse">
            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("Home", "Home", "Home")</li>
                <li>@Html.ActionLink("Profile", "Profile", "Profile")</li>
            </ul>
        </div>
        <div  class="navbar-collapse collapse navbar-right profile-collapse">
            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("Profile", "Profile", "Profile")</li>
                <li>@Html.ActionLink("Settings", "Settings", "ManageSettings")</li>
            </ul>
        </div>
        <div  class="navbar-collapse collapse navbar-right notifications-collapse">
            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("Notifications", " ", "Profile")</li>
            </ul>
        </div>
        <div  class="navbar-collapse collapse navbar-right help-collapse">
            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("Help", " ", "Profile")</li>
            </ul>
        </div>
    </div>
</div>

JS:

<script>    
    $(function () {
        $(document).click(function (event) {
            $('.navbar-collapse').collapse('hide');
        });
    });
</script>

附图

(现在请忽略样式问题,一旦菜单正常工作,我将处理样式)

导航物品关闭:qazxsw poi

点击汉堡菜单,所有导航项目打开enter image description here

应该只有一个菜单打开一次enter image description here

我到处搜索,但找不到适合我的答案。我正在使用其他地方建议的数据父级,并为每个菜单提供唯一的数据目标。

任何帮助,将不胜感激。

javascript jquery html css twitter-bootstrap
1个回答
0
投票

我认为你可以根据这个例子自己简化它:enter image description here

在实践中:

dropdown example
.navbar-brand-centered {
    position: absolute;
    left: 50%;
    width: 160px;
    text-align: center;
}
.navbar>.container .navbar-brand-centered {
    margin-left: -80px!important;
}

.navbar-nav>li, .navbar-nav{
  float: left !important;
}

.navbar-right {
  float: right !important;
}

.nav.navbar-nav .dropdown {
  width: 48px;
  position: relative;
}

.nav.navbar-nav {
  margin: 0;
}

.nav.navbar-nav>li>a {
  padding-top: 15px;
  padding-bottom: 15px;
}

.nav.navbar-nav .dropdown.open .dropdown-menu li a:hover {
  color: #262626;
  text-decoration: none;
  background-color: #f5f5f5;
}

.nav.navbar-nav .dropdown ul {
    position: absolute;
    top: 100%;
    left: 0;
    float: left;
    background-color: #fff;
    border: 1px solid #ccc;
    border: 1px solid rgba(0,0,0,.15);
    background-clip: padding-box;
    box-shadow: rgba(0, 0, 0, 0.176) 0px 6px 12px;
    
}

.nav.navbar-nav.navbar-right .dropdown ul {
    right: 0;
    left: auto;
}

而且我不确定为什么你需要底部的脚本。

编辑:更改为更具响应性

© www.soinside.com 2019 - 2024. All rights reserved.