具有多个折叠的Bootstrap 3 RC2 Navbar

时间:2013-08-16 08:30:59

标签: twitter-bootstrap navbar twitter-bootstrap-3

我正在试图弄清楚如何在Bootstrap 3 RC2中获得以下布局。

其中左侧项目是主要导航UL,侧面图标是附加UL或仅仅是一组共享外观的链接,但为其内容提供下拉列表或隐藏/显示切换(列表为小组,但希望为其他人进行互动搜索和购物车展示。)

目前,当我执行此代码时,此功能正常:

<div class="nav-wrapper" style="height: 56px;">
        <div class="nav-primary affix-top">
            <nav class="navbar" role="navigation">
                <div class="container">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">


                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-primary-collapse">
                            <span class="sr-only">Primary navigation</span>
                            <i class="icon-list"></i>
                        </button>

                        <button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target=".navbar-cart-collapse">
                            <span class="sr-only">Itinerary navigation</span>
                            <span class="icon-calendar-empty"></span>
                        </button>

                        <button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target=".navbar-user-collapse">
                            <span class="sr-only">User navigation</span>
                            <span class="icon-user"></span>
                        </button>

                        <button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target=".navbar-search-collapse">
                            <span class="sr-only">Search navigation</span>
                            <span class="icon-search"></span>
                        </button>
                    </div>

                    <div class="row">
                        <!-- Collect the nav links, forms, and other content for toggling -->
                        <div class="col-lg-8 col-sm-8 navbar-collapse navbar-primary-collapse in" style="height: auto;">

            <ul id="navPrimary" class="nav navbar-nav">

        <li class="first" id="navRegions"><a href="/regions/">Regions</a></li>

        <li id="navWineries"><a href="/wineries/">Wineries</a></li>

        <li id="navExplore"><a href="/explore/">Explore</a></li>

        <li class="last" id="navEvents"><a href="/events/">Events</a></li>
        </ul> 
                      </div><!-- /.navbar-primary-collapse -->

                        <!-- Collect the nav links, forms, and other content for toggling -->
                        <div class="col-lg-4 col-sm-4 pull-right collapse navbar-collapse">
                            <ul class="nav navbar-nav navbar-right">
                                <li>
                                    <a href="#"><i class="icon-search"></i></a>
                                    <div id="prime-nav-searchform" class="dropdown-menu">   <form method="get" action="http://antonibotev.com/themes/nova/" class="search-form">
                                            <i class="icon-search searchform-icon"></i>
                                            <input class="bluebox-search-input" type="text" name="s" value="Search..." onfocus="" onblur="" autocomplete="off" data-view-all-title="Show All Results" data-original-title="">
                                            <input type="submit" class="submit" value="" onfocus="" onblur="">
                                            <div class="search-form-autocomplete active">
                                                <div class="search-results-autocomplete">

                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </li>
                                <li class="dropdown"><a href="#" class="dropdown-toggle"><i class="icon-user"></i>  <b class="caret"></b></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="#">Log In</a></li>
                                        <li><a href="#">Sign Up</a></li>
                                        <li><a href="#">How It Works</a></li>
                                        <li><a href="#">Need Help?</a></li>
                                    </ul>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-calendar-empty"></i> <span>4</span></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="#">View Itinerary</a></li>
                                        <li><a href="#">Check Out</a></li>
                                        <li><a href="#">Need Help?</a></li>
                                    </ul>
                                </li>
                            </ul>
                      </div><!-- /.navbar-collapse -->
                    </div>



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

这适用于初始崩溃,但我需要额外的,但目前他们需要住在相同的UL,这显然是创建其他3个崩溃div的问题。

如果您点击搜索或购物车,我甚至可以使用代码来切换折叠。它只会一次显示一个:打开一个并关闭另一个

// mobile toggles - make sure when one navbar-collapse is open, that the others are closed
$('.navbar-collapse').on('show.bs.collapse', function (e) {
    // hide open menus
    $('.navbar-collapse').each(function(){
        if ($(this).hasClass('in')) {
            $(this).collapse('toggle');
        }
    });
});

小和xs断点应该显示相同的布局,但当然用图标替换主导航。想法是你有4个图标只需点击或点击切换各自的菜单,无论这些菜单是包含列表还是只包含搜索表单。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我认为我制作的NAVBAR非常接近你所寻找的东西。我以前发过这个答案,但它很适用于你的问题。

此示例显示了如何获得您想要的任何类型的“vanilla bootstrap”NAVBAR配置。它包括一个站点标题,左右对齐的折叠和非折叠菜单项以及静态文本。该示例还有一个带图标的下拉菜单。

请务必阅读评论,以便更全面地了解您可以更改的内容。享受!

小提琴:http://jsfiddle.net/nomis/n9KtL/1/

<nav role="navigation" class="navbar navbar-default navbar-fixed-top">
  <div class="container">

    <!-- Title -->
    <div class="navbar-header pull-left">
      <a href="/" class="navbar-brand">GNOMIS</a>
    </div>

    <!-- 'Sticky' (non-collapsing) right-side menu item(s) -->
    <div class="navbar-header pull-right">
      <ul class="nav pull-left">
        <!-- This works well for static text, like a username -->
        <li class="navbar-text pull-left">User Name</li>
        <!-- Add any additional bootstrap header items.  This is a drop-down from an icon -->
        <li class="dropdown pull-right">
          <a href="#" data-toggle="dropdown" style="color:#777; margin-top: 5px;" class="dropdown-toggle"><span class="glyphicon glyphicon-user"></span><b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li>
              <a href="/users/id" title="Profile">Profile</a>
            </li>
            <li>
              <a href="/logout" title="Logout">Logout </a>
            </li>
          </ul>
        </li>
      </ul>

      <!-- Required bootstrap placeholder for the collapsed menu -->
      <button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
    </div>

    <!-- The Collapsing items            navbar-left or navbar-right -->
    <div class="collapse navbar-collapse navbar-left">
      <!--                      pull-right keeps the drop-down in line -->
      <ul class="nav navbar-nav pull-right">
        <li><a href="/news">News</a></li>
        <li><a href="/Shop">Shop</a></li>
      </ul>
    </div>

    <!-- Additional navbar items -->
    <div class="collapse navbar-collapse navbar-right">
      <!--                      pull-right keeps the drop-down in line -->
      <ul class="nav navbar-nav pull-right">
        <li><a href="/locator">Locator</a></li>
        <li><a href="/extras">Extras</a></li>
      </ul>
    </div>
  </div>
</nav>