Multiple grouped dropdown buttons in a row with Twitter Bootstrap 2.x

北战南征 提交于 2020-01-03 08:49:10

问题


It there an easy way to get button dropdowns grouped like button-groups with Twitter Bootstrap?

This code

<div class="btn-toolbar">
<div class="btn-group">
    <div class="btn-group">
        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
            January
            <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
            <li><a href="#" class="active">January</a></li>
            <li><a href="#">February</a></li>
            <!-- ... -->
        </ul>
    </div>
    <div class="btn-group">
        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
            2012
            <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
            <li><a href="#" rel="2012" class="active">2012</a></li>
            <li><a href="#" rel="2011">2011</a></li>
            <li><a href="#" rel="2010">2010</a></li>
            <li><a href="#" rel="2009">2009</a></li>
        </ul>
    </div>
</div>

Result


回答1:


Solution is place dropdown button into grouped button.

Here is an example: http://jsfiddle.net/RayZ/CgBTn/49/

    <div class="btn-group"> <!-- group container for buttons merging -->
        <div class="btn btn-group">  <!-- button and dropdown group in one -->
            <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                One 
                <span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
                <li><a href="#">foo</a></li>
            </ul>
        </div>
        <div class="btn btn-group">
            <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                Two
                <span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
                <li><a href="#">foo</a></li>
            </ul>
        </div>
    </div>

Some CSS tweaks:

.btn-group.btn {   border: 0;   padding: 0; }
.btn-group.btn > .btn { border-radius: 0 }
.btn-group.btn > .dropdown-menu {  text-align: left; }
.btn-group.btn:first-child > .btn {
  -webkit-border-radius: 4px 0 0 4px;
     -moz-border-radius: 4px 0 0 4px;
          border-radius: 4px 0 0 4px;
}

.btn-group.btn:last-child > .btn {
  -webkit-border-radius: 0 4px 4px 0;
     -moz-border-radius: 0 4px 4px 0;
          border-radius: 0 4px 4px 0;
}



来源:https://stackoverflow.com/questions/13763176/multiple-grouped-dropdown-buttons-in-a-row-with-twitter-bootstrap-2-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!