dropdowns.html 8.05 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
2
3
4
5
6
<div class="bs-docs-section">
  <h1 id="dropdowns" class="page-header">Dropdowns</h1>

  <p class="lead">Toggleable, contextual menu for displaying lists of links. Made interactive with the <a href="../javascript/#dropdowns">dropdown JavaScript plugin</a>.</p>

  <h3 id="dropdowns-example">Example</h3>
7
  <p>Wrap the dropdown's trigger and the dropdown menu within <code>.dropdown</code>, or another element that declares <code>position: relative;</code>. Then add the menu's HTML. Dropdown menus can also be triggered above elements by adding <code>.dropup</code> to the parent.</p>
8
  <div class="bs-example" data-example-id="static-dropdown">
Mark Otto's avatar
Mark Otto committed
9
    <div class="dropdown clearfix">
10
      <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
11
        Dropdown
Mark Otto's avatar
Mark Otto committed
12
13
14
15
16
17
18
19
        <span class="caret"></span>
      </button>
      <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
      </ul>
    </div>
20
21
22
23
24
25
26
27
28
29
30
    <div class="dropup clearfix">
      <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-expanded="true">
        Dropdown
        <span class="caret"></span>
      </button>
      <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu2">
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
      </ul>
    </div>
Mark Otto's avatar
Mark Otto committed
31
32
33
  </div><!-- /example -->
{% highlight html %}
<div class="dropdown">
34
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
35
    Dropdown
Mark Otto's avatar
Mark Otto committed
36
37
38
39
40
41
42
43
44
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
  </ul>
</div>
45
46
47
48
49
50
51
52
53
54
55
56
<div class="dropup">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-expanded="true">
    Dropdown
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu2">
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
  </ul>
</div>
Mark Otto's avatar
Mark Otto committed
57
58
59
60
{% endhighlight %}

  <h3 id="dropdowns-alignment">Alignment</h3>
  <p>By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. Add <code>.dropdown-menu-right</code> to a <code>.dropdown-menu</code> to right align the dropdown menu.</p>
Chris Rebert's avatar
Chris Rebert committed
61
  <div class="bs-callout bs-callout-warning" id="callout-dropdown-positioning">
Mark Otto's avatar
Mark Otto committed
62
63
64
    <h4>May require additional positioning</h4>
    <p>Dropdowns are automatically positioned via CSS within the normal flow of the document. This means dropdowns may be cropped by parents with certain <code>overflow</code> properties or appear out of bounds of the viewport. Address these issues on your own as they arise.</p>
  </div>
Chris Rebert's avatar
Chris Rebert committed
65
  <div class="bs-callout bs-callout-warning" id="callout-dropdown-pull-right">
Mark Otto's avatar
Mark Otto committed
66
67
68
69
70
71
72
73
74
75
76
77
78
    <h4>Deprecated <code>.pull-right</code> alignment</h4>
    <p>As of v3.1.0, we've deprecated <code>.pull-right</code> on dropdown menus. To right-align a menu, use <code>.dropdown-menu-right</code>. Right-aligned nav components in the navbar use a mixin version of this class to automatically align the menu. To override it, use <code>.dropdown-menu-left</code>.</p>
  </div>
{% highlight html %}
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dLabel">
  ...
</ul>
{% endhighlight %}

  <h3 id="dropdowns-headers">Headers</h3>
  <p>Add a header to label sections of actions in any dropdown menu.</p>
  <div class="bs-example">
    <div class="dropdown clearfix">
79
      <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu3" data-toggle="dropdown" aria-expanded="true">
Mark Otto's avatar
Mark Otto committed
80
81
82
        Dropdown
        <span class="caret"></span>
      </button>
83
      <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu3">
Mark Otto's avatar
Mark Otto committed
84
85
86
87
88
89
90
91
92
93
        <li role="presentation" class="dropdown-header">Dropdown header</li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
        <li role="presentation" class="dropdown-header">Dropdown header</li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
      </ul>
    </div>
  </div><!-- /example -->
{% highlight html %}
94
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu3">
95
  ...
Mark Otto's avatar
Mark Otto committed
96
97
  <li role="presentation" class="dropdown-header">Dropdown header</li>
  ...
98
99
100
101
102
103
104
</ul>
{% endhighlight %}

  <h3 id="dropdowns-divider">Divider</h3>
  <p>Add a divider to separate series of links in a dropdown menu.</p>
  <div class="bs-example">
    <div class="dropdown clearfix">
105
      <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenuDivider" data-toggle="dropdown" aria-expanded="true">
106
107
108
        Dropdown
        <span class="caret"></span>
      </button>
Mark Otto's avatar
Mark Otto committed
109
      <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuDivider">
110
111
112
113
114
115
116
117
118
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
        <li role="presentation" class="divider"></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
      </ul>
    </div>
  </div><!-- /example -->
{% highlight html %}
Mark Otto's avatar
Mark Otto committed
119
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuDivider">
120
  ...
Mark Otto's avatar
Mark Otto committed
121
122
123
124
125
126
127
128
129
  <li role="presentation" class="divider"></li>
  ...
</ul>
{% endhighlight %}

  <h3 id="dropdowns-disabled">Disabled menu items</h3>
  <p>Add <code>.disabled</code> to a <code>&lt;li&gt;</code> in the dropdown to disable the link.</p>
  <div class="bs-example">
    <div class="dropdown clearfix">
130
      <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu4" data-toggle="dropdown" aria-expanded="true">
Mark Otto's avatar
Mark Otto committed
131
132
133
        Dropdown
        <span class="caret"></span>
      </button>
134
      <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu4">
Mark Otto's avatar
Mark Otto committed
135
136
137
138
139
140
141
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Regular link</a></li>
        <li role="presentation" class="disabled"><a role="menuitem" tabindex="-1" href="#">Disabled link</a></li>
        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another link</a></li>
      </ul>
    </div>
  </div><!-- /example -->
{% highlight html %}
142
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu4">
Mark Otto's avatar
Mark Otto committed
143
144
145
146
147
148
  <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Regular link</a></li>
  <li role="presentation" class="disabled"><a role="menuitem" tabindex="-1" href="#">Disabled link</a></li>
  <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another link</a></li>
</ul>
{% endhighlight %}
</div>