0

I'm trying to achieve a nav menu similar to the examples but with a split-button drop-down:

"Tabs with dropdowns" http://twitter.github.io/bootstrap/components.html#navs

http://twitter.github.io/bootstrap/components.html#navbar

I can have a split button, or I can have a tab with a dropdown, but I can't seem to combine the two. Is this possible?

Tabs with dropdowns:

<div class="">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#">Home</a></li>
        <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tab2 <b class="caret"></b></a>
            <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Separated link</a></li>
            </ul>
        </li>
        <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tab3<b class="caret"></b></a>
            <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Separated link</a></li>
            </ul>
        </li>
    </ul>
</div>

Split Button:

<div class="btn-toolbar" style="margin: 0;">
          <div class="btn-group">
            <button class="btn dropdown-toggle" data-toggle="dropdown">Action <span class="caret"></span></button>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li class="divider"></li>
              <li><a href="#">Separated link</a></li>
            </ul>
          </div>
</div>
4

2 回答 2

0

所以你的最终结果应该是一个拆分按钮而不是一个下拉菜单,对吗?你试过这个吗?(没有测试)

    <div>
        <ul class="nav nav-tabs">
            <li class="active">
                <button class="btn dropdown-toggle" data-toggle="dropdown">Home<span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a href="#">Action</a></li>
                  <li><a href="#">Another action</a></li>
                  <li><a href="#">Something else here</a></li>
                  <li class="divider"></li>
                  <li><a href="#">Separated link</a></li>
                </ul>
            </li>
        </ul>
    </div>
于 2013-04-24T10:57:47.680 回答
0

我现在已经够近了——只需要稍微改变一下样式。

这是HTML:

    <!DOCTYPE html>
    <html lang="en">
    <head>
<meta charset="utf-8">
<title>Test Bootstrap</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="content/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="content/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-static-top">
    <div class="navbar-inner">
        <div class="container tabbable">
            <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="brand" href="#">ProjectName</a>
            <div class="nav-collapse collapse">
                <ul class="nav">
                    <li class="active tabbable"><a href="#tab1" data-toggle="tab">tab1</a></li>
                    <li class="tabbable"><a href="#tab2" data-toggle="tab">tab2</a></li>
                    <li class="tabbable" id="tabarea3">
                        <!--<div class="btn-group" data-toggle="buttons-radio">-->
                        <div class="btn-group">
                            <a class="btn" id="tab3" href="#tab3" data-toggle="tab">Tab3</a>
                            <button id="tab3button" class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
                            <ul class="dropdown-menu">
                                <li><a href="#">Action</a></li>
                                <li><a href="#">Another action</a></li>
                                <li><a href="#">Something else here</a></li>
                                <li class="divider"></li>
                                <li><a href="#">Separated link</a></li>
                            </ul>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>

<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->

<script src="content/bootstrap/js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="content/bootstrap/js/bootstrap.js" type="text/javascript"></script>
<script src="content/bootstrap/js/custom.js" type="text/javascript"></script>

一些 jquery 取消选择拆分按钮选项卡(custom.js):

 $(document).ready(function () {
        var $tabs = $('.tabbable li');
        $tabs.on('click', function (sender) {
            if($('#tab3').hasClass('active'))
            {
                $('#tab3').removeClass('active');
            }
        });
    });
于 2013-04-24T15:22:53.343 回答