Bootstrap双导航栏没有正确折叠

时间:2015-02-18 13:58:12

标签: css asp.net twitter-bootstrap navbar

我在建立双导航栏时从这个链接: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>

1 个答案:

答案 0 :(得分:0)

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

<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 demo navbars创建了一个双导航栏的演示,该演示使用一个按钮(我使用)折叠:

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,

-Ted