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

308 lines
13 KiB
Markdown
Raw Normal View History

2014-07-13 09:59:31 +02:00
---
layout: docs
2014-07-13 09:59:31 +02:00
title: Button dropdown
group: components
2014-07-13 09:59:31 +02:00
---
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]({{ site.baseurl }}/components/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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-03-17 03:03:53 +01:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-03-17 03:03:53 +01:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-03-17 03:03:53 +01:00
</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>
<div class="dropdown-menu">
2014-03-17 03:03:53 +01:00
...
</div>
2014-03-17 03:03:53 +01:00
</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>
<div class="dropdown-menu">
2014-03-17 03:03:53 +01:00
...
</div>
2014-03-17 03:03:53 +01:00
</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>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
2014-07-13 10:23:29 +02:00
</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>
<div class="dropdown-menu">
2014-03-17 03:03:53 +01:00
<!-- Dropdown menu links -->
</div>
2014-03-17 03:03:53 +01:00
</div>
{% endhighlight %}