0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-02 14:24:19 +01:00
Bootstrap/docs/components/button-dropdown.md

331 lines
13 KiB
Markdown
Raw Normal View History

2014-07-13 09:59:31 +02:00
---
layout: page
title: Button dropdown
---
Use any button to trigger a dropdown menu by placing it within a `.btn-group` and providing the proper dropdown menu markup.
2014-03-17 03:03:53 +01:00
{% callout danger %}
#### Plugin dependency
Button dropdowns require the [dropdown plugin](../javascript/#dropdowns) to be included in your version of Bootstrap.
{% endcallout %}
2014-03-17 03:03:53 +01:00
2015-05-29 10:58:52 +02:00
## Contents
* Will be replaced with the ToC, excluding the "Contents" header
{:toc}
2014-07-13 10:23:29 +02:00
### Single button dropdowns
Turn a button into a dropdown toggle with some basic markup changes.
<div class="bd-example">
2014-07-13 10:23:29 +02:00
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Default</button>
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Primary</button>
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Success</button>
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Info</button>
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-warning dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Warning</button>
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Danger</button>
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
</div>
2014-03-17 03:03:53 +01:00
{% highlight html %}
<!-- Single button -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Action
2014-03-17 03:03:53 +01:00
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-03-17 03:03:53 +01:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-03-17 03:03:53 +01:00
<li><a href="#">Separated link</a></li>
</ul>
</div>
{% endhighlight %}
2014-07-13 10:23:29 +02:00
### Split button dropdowns
2015-03-09 15:50:40 +01:00
Similarly, create split button dropdowns with the same markup changes, only with a separate button.
2014-07-13 10:23:29 +02:00
<div class="bd-example">
2014-07-13 10:23:29 +02:00
<div class="btn-group">
<button type="button" class="btn btn-secondary">Default</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
<button type="button" class="btn btn-primary">Primary</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
<button type="button" class="btn btn-success">Success</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
<button type="button" class="btn btn-info">Info</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
<button type="button" class="btn btn-warning">Warning</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-warning dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group">
<button type="button" class="btn btn-danger">Danger</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
</div>
{% highlight html %}
<!-- Split button -->
<div class="btn-group">
<button type="button" class="btn btn-danger">Action</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div>
{% endhighlight %}
### Sizing
Button dropdowns work with buttons of all sizes.
<div class="bd-example">
2014-07-13 10:23:29 +02:00
<div class="btn-toolbar" role="toolbar">
2014-03-17 03:03:53 +01:00
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button class="btn btn-secondary btn-lg dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
Large button
2014-03-17 03:03:53 +01:00
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-03-17 03:03:53 +01:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-03-17 03:03:53 +01:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
2014-07-13 10:23:29 +02:00
</div><!-- /btn-toolbar -->
<div class="btn-toolbar" role="toolbar">
2014-03-17 03:03:53 +01:00
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
Small button
2014-03-17 03:03:53 +01:00
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-03-17 03:03:53 +01:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-03-17 03:03:53 +01:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
2014-07-13 10:23:29 +02:00
</div><!-- /btn-toolbar -->
<div class="btn-toolbar" role="toolbar">
2014-03-17 03:03:53 +01:00
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button class="btn btn-secondary btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
Extra small button
2014-03-17 03:03:53 +01:00
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-03-17 03:03:53 +01:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-03-17 03:03:53 +01:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
2014-07-13 10:23:29 +02:00
</div><!-- /btn-toolbar -->
</div><!-- /example -->
2014-03-17 03:03:53 +01:00
{% highlight html %}
<!-- Large button group -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button class="btn btn-secondary btn-lg dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Large button
2014-03-17 03:03:53 +01:00
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-03-17 03:03:53 +01:00
...
</ul>
</div>
<!-- Small button group -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Small button
2014-03-17 03:03:53 +01:00
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-03-17 03:03:53 +01:00
...
</ul>
</div>
<!-- Extra small button group -->
<div class="btn-group">
2015-06-19 08:56:43 +02:00
<button class="btn btn-secondary btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Extra small button
2014-03-17 03:03:53 +01:00
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-03-17 03:03:53 +01:00
...
</ul>
</div>
{% endhighlight %}
2014-07-13 10:23:29 +02:00
### Dropup variation
Trigger dropdown menus above elements by adding `.dropup` to the parent.
<div class="bd-example">
2014-07-13 10:23:29 +02:00
<div class="btn-toolbar" role="toolbar">
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary">Dropup</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
<div class="btn-group dropup">
<button type="button" class="btn btn-primary">Right dropup</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-07-13 10:23:29 +02:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu dropdown-menu-right">
2014-07-13 10:23:29 +02:00
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
2015-06-19 08:56:43 +02:00
<li role="separator" class="divider"></li>
2014-07-13 10:23:29 +02:00
<li><a href="#">Separated link</a></li>
</ul>
</div><!-- /btn-group -->
</div>
</div>
2014-03-17 03:03:53 +01:00
{% highlight html %}
<div class="btn-group dropup">
2014-07-09 02:14:14 +02:00
<button type="button" class="btn btn-secondary">Dropup</button>
2015-06-19 08:56:43 +02:00
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
2014-03-17 03:03:53 +01:00
<span class="sr-only">Toggle Dropdown</span>
</button>
2015-06-19 08:56:43 +02:00
<ul class="dropdown-menu">
2014-03-17 03:03:53 +01:00
<!-- Dropdown menu links -->
</ul>
</div>
{% endhighlight %}