Bootstrap 双导航栏无法正确折叠

Bootstrap double navbar not collapsing properly

我从这个 link: http://www.bootply.com/lJgThXaVXi# 得到了帮助,当我构建我的双导航栏时,我得到的效果与这个例子中的一样。但是,当我的导航栏折叠时,我得到 2 个按钮而不是 1 个(该示例仅获得一个显示来自两个导航栏的数据的折叠按钮)。

此外,当我按下 navbar1 的折叠按钮时,它会显示 navbar1 中的所有内容,但是当我按下 navbar2 中的折叠按钮时,会触发折叠- navbar1 的按钮。我一直在详细检查示例中的代码,但找不到我做的任何不同的事情。

基本上我希望有 1 个折叠按钮显示来自两个导航栏的所有信息。

代码:

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a href="/Default.aspx" class="navbar-brand">Logo</a>

                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                </div>
                <div class="collapse navbar-collapse">

                    <ul class="nav navbar-nav navbar-left">
                        <li><a href="/AddSite.aspx">Add site</a></li>
                    </ul>

                    <div class="col-sm-3 col-md-3" style="background-color:red">
                        <div class="navbar-form" role="search">
                            <div class="input-group">
                                <asp:TextBox ID="TextBoxSearch" CssClass="form-control" placeholder="Search" runat="server"></asp:TextBox>
                                <div class="input-group-btn">
                                    <asp:LinkButton ID="LinkButtonSearch" CssClass="btn btn-default" OnClick="search_click" runat="server"><i class="glyphicon glyphicon-search"></i></asp:LinkButton>
                                </div>
                            </div>
                        </div>
                    </div>

                    <ul class="nav navbar-nav navbar-right" style="background-color:blue">
                        <li >
                            <asp:LinkButton ID="LinkButtonRegister" runat="server" OnClick="Register">Register</asp:LinkButton></li>
                        <li>
                            <asp:LinkButton ID="LinkButtonLogin" data-toggle="modal" data-target="#loginModal" runat="server">Log in</asp:LinkButton></li>
                        <li>
                            <asp:LinkButton ID="LinkButtonLogout" runat="server" OnClick="Logout">Log out</asp:LinkButton></li>
                    </ul>
                </div>
            </div>
        </div>
        <!-- END OF FIRST NAVBAR -->
        <div class="navbar navbar-inverse navbar-static-top" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                </div>
                <div class="collapse navbar-collapse">

                    <ul class="nav navbar-nav navbar-left">
                        <li><a href="/AddSite.aspx">Add site</a></li>
                    </ul>

                    </div>
                </div>
            </div>

您的代码中有两个折叠按钮。删除一个(其中一个):

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
</button>

此外,我使用 bootstrap 演示导航栏创建了一个双导航栏的演示,该演示使用一个按钮折叠(我使用):

My Bootstrap Double Top Nav Bars

相关代码如下:

<div class="navwrap">
    <!-- first navbar -->
    <div class="navbar navbar-default navbar-static-top no-bottom-margin">
        <div class="container">
            <div class="navbar-header">
                <span class="navbar-brand">Brand</span>
                <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>

            <nav class="collapse navbar-collapse" role="navigation">
                <div class="navbar-right">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                        <li><a href="#">Link</a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="#">Action</a></li>
                                <li><a href="#">Another action</a></li>
                                <li><a href="#">Something else here</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </nav>
        </div>
    </div>
    <!-- second navbar -->
    <div class="navbar-inverse">
        <div class="container">
            <nav class="collapse navbar-collapse nested-nav global-nav" role="navigation">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                    <li><a href="#">Link</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</div>

加上这个 CSS 规则:

.no-bottom-margin{margin-bottom:0;}

HTH,

-泰德