Bootstrap - 导航+子导航显示和隐藏点击

时间:2013-06-19 10:56:33

标签: twitter-bootstrap drop-down-menu tabs nav

我正在尝试制作与下拉列表具有类似效果的导航,但不是带有子菜单的框,它将显示标签。我做了它,它工作得很好 - 我唯一的问题是,当我点击按钮时,子菜单会显示(这很好)但是当我再次点击它时它不会关闭。所以我想做的是:点击按钮 - 子菜单显示 - 再次点击相同的按钮,子菜单隐藏。

<!-- Navigation bar -->
        <div class="container-narrow">
          <ul class="nav nav-pills nav-main">
            <li class="nav-size active"><a href="index.php">Home</a></li>
            <li class="nav-size"><a href="#tab1" data-toggle="tab">About</a></li>
            <li class="nav-size"><a href="#">Services</a></li>
            <li class="nav-size"><a href="#">Downloads</a></li>
                <li class="pull-right"><a href="#tab2" data-toggle="tab"><img src="img/flags/flags12.png" alt="flags" /></a></li>
                <li class="pull-right"><a href="#">Register</a></li>
                <li class="pull-right"><a href="#">Login</a></li>
          </ul>

                    <div class="tab-content">
                        <div class="tab-pane" id="tab1">
                            <ul class="nav nav-tabs nav-sub">
                                <li><a href="#">Services</a></li>
                                <li><a href="#">Site Services</a></li>
                                <li><a href="#">O'Leary Group</a></li>
                            </ul>
                        </div>
                    </div>

                    <div class="tab-content">
                        <div class="tab-pane" id="tab2">
                            <ul class="nav nav-tabs nav-sub">
                                <li class="pull-right"><a href="#"><img src="img/flags/en.png" /> English</a></li>
                                <li class="pull-right"><a href="#"><img src="img/flags/fr.png" /> French</a></a></li>
                                <li class="pull-right"><a href="#"><img src="img/flags/de.png" /> German</a></a></li>
                                <li class="pull-right"><a href="#"><img src="img/flags/pl.png" /> Polish</a></a></li>
                            </ul>
                        </div>
                    </div>
      </div><!-- / Navigation bar -->

1 个答案:

答案 0 :(得分:1)

可能值得调查collapse plugin。您可以通过执行以下操作使其工作

<!-- Navigation bar -->
<div class="container-narrow">
    <ul class="nav nav-pills nav-main">
        <li class="nav-size active"><a href="index.php">Home</a></li>
        <li class="nav-size"><a href="#tab1" data-toggle="collapse" data-target="#tab1">About</a></li>
        <li class="nav-size"><a href="#">Services</a></li>
        <li class="nav-size"><a href="#">Downloads</a></li>
        <li class="pull-right"><a href="#tab2" data-toggle="tab"><img src="img/flags/flags12.png" alt="flags" /></a></li>
        <li class="pull-right"><a href="#">Register</a></li>
        <li class="pull-right"><a href="#">Login</a></li>
    </ul>

    <div class="collapse" id="tab1">
        <div class="tab-pane" >
            <ul class="nav nav-tabs nav-sub">
                <li><a href="#">Services</a></li>
                <li><a href="#">Site Services</a></li>
                <li><a href="#">O'Leary Group</a></li>
            </ul>
        </div>
    </div>

    <div class="tab-content">
        <div class="tab-pane" id="tab2">
            <ul class="nav nav-tabs nav-sub">
                <li class="pull-right"><a href="#"><img src="img/flags/en.png" /> English</a></li>
                <li class="pull-right"><a href="#"><img src="img/flags/fr.png" /> French</a></a></li>
            <li class="pull-right"><a href="#"><img src="img/flags/de.png" /> German</a></a></li>
        <li class="pull-right"><a href="#"><img src="img/flags/pl.png" /> Polish</a></a></li>
</ul>
</div>
</div>
</div><!-- / Navigation bar -->

这并不完美,但似乎标签不会显示您需要OOTB的行为。