buttons.md 11.4 KB
Newer Older
C
chomik 已提交
1 2
---
title: Buttons
3 4
icon: fe fe-plus-square
description: Use Bootstrap’s custom button styles for actions in forms, dialogs, and more. Includes support for a handful of contextual variations, sizes, states, and more.
C
codecalm 已提交
5
bootstrap-link: components/buttons/
C
codecalm 已提交
6
done: true
C
chomik 已提交
7 8
---

9 10 11 12
### Button tag

The `.btn` classes are designed to be used with the `<button>` element. However, you can also use these classes on `<a>` or `<input>` elements (though some browsers may apply a slightly different rendering).

C
codecalm 已提交
13
{% capture code %}
C
codecalm 已提交
14
<a href="#" class="btn btn-primary" role="button">Link</a>
15
<button class="btn btn-primary">Button</button>
C
codecalm 已提交
16 17 18
<input type="button" class="btn btn-primary" value="Input"/>
<input type="submit" class="btn btn-primary" value="Submit"/>
<input type="reset" class="btn btn-primary" value="Reset"/>
C
codecalm 已提交
19 20 21
{% endcapture  %}
{% include example.html code=code wrapper="btn-list" centered=true %}

22 23 24 25 26

### Button variations

Use any of the available button classes to quickly create a styled button . We provide a variety of colors for you to express different emotions.

C
codecalm 已提交
27
{% capture code %}
C
codecalm 已提交
28
{% for button in site.button-variants %}
D
Dawid Harat 已提交
29 30
{% assign btn-color = button[1].class %}
{% assign btn-title = button[1].title %}
C
codecalm 已提交
31
{% include ui/button.html color=btn-color text=btn-title %}
32
{% endfor %}
C
codecalm 已提交
33 34
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
35 36 37 38

### Disabled buttons

Make buttons look inactive by adding the disabled boolean attribute to any `.btn` element. `<a>`s don’t support the disabled attribute, so you must add the `.disabled` class to make it visually appear disabled.
D
Dawid Harat 已提交
39

C
codecalm 已提交
40
{% capture code %}
C
codecalm 已提交
41
{% for button in site.button-variants %}
D
Dawid Harat 已提交
42 43
{% assign btn-color = button[1].class %}
{% assign btn-title = button[1].title %}
C
codecalm 已提交
44
{% include ui/button.html color=btn-color text=btn-title disabled=true %}
45
{% endfor %}
C
codecalm 已提交
46 47
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
48 49 50 51 52

### Color variations

The classic button, in different colors.

C
codecalm 已提交
53
{% capture code %}
54
{% for button in site.colors %}
C
codecalm 已提交
55
<a href="#" class="btn btn-{{ button[0] }}">{{ button[1].title }}</a>
56
{% endfor %}
C
codecalm 已提交
57 58
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
C
codecalm 已提交
59 60 61 62 63 64 65 66 67 68 69

### Ghost Buttons

Use `.btn-ghost-*` class for ghost buttons.

{% capture code %}
{% for button in site.button-variants %}
<a href="#" class="btn btn-ghost-{{ button[0] }}">{{ button[1].title }}</a>
{% endfor %}
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
70 71 72 73 74

### Square buttons

Add `.btn-square` to button to remove border-radius.

C
codecalm 已提交
75
{% capture code %}
C
codecalm 已提交
76
{% for button in site.button-variants %}
D
Dawid Harat 已提交
77 78
{% assign btn-color = button[1].class %}
{% assign btn-title = button[1].title %}
C
codecalm 已提交
79
{% include ui/button.html color=btn-color text=btn-title square=true %}
80
{% endfor %}
C
codecalm 已提交
81 82
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
83 84 85 86 87

### Pill buttons

Add `.btn-pill` class to any button to make them more rounded.

C
codecalm 已提交
88
{% capture code %}
C
codecalm 已提交
89
{% for button in site.button-variants %}
D
Dawid Harat 已提交
90 91
{% assign btn-color = button[1].class %}
{% assign btn-title = button[1].title %}
C
codecalm 已提交
92
{% include ui/button.html color=btn-color text=btn-title pill=true %}
93
{% endfor %}
C
codecalm 已提交
94 95
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
96 97 98 99 100

### Outline buttons

In need of a button, but not the hefty background colors they bring? Replace the default modifier classes with the `.btn-outline-*` ones to remove all background images and colors on any button.

C
codecalm 已提交
101
{% capture code %}
C
codecalm 已提交
102
{% for button in site.button-variants %}
D
Dawid Harat 已提交
103 104
{% assign btn-color = button[1].class %}
{% assign btn-title = button[1].title %}
C
codecalm 已提交
105
{% include ui/button.html text=btn-title color=btn-color outline=true %}
M
mrszympek 已提交
106
{% endfor %}
C
codecalm 已提交
107 108
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
M
mrszympek 已提交
109

110 111 112 113
### Button size

Add `.btn-lg` or `.btn-sm` for additional sizes.

C
codecalm 已提交
114
{% capture code %}
115 116
<button type="button" class="btn btn-primary btn-lg">Large button</button>
<button type="button" class="btn btn-secondary btn-lg">Large button</button>
C
codecalm 已提交
117 118
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
119

C
codecalm 已提交
120
{% capture code %}
121 122
<button type="button" class="btn btn-primary btn-sm">Small button</button>
<button type="button" class="btn btn-secondary btn-sm">Small button</button>
C
codecalm 已提交
123 124
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
125 126 127

Create block level buttons—those that span the full width of a parent—by adding `.btn-block`.

C
codecalm 已提交
128
{% capture code %}
129 130
<button type="button" class="btn btn-primary btn-block">Block level button</button>
<button type="button" class="btn btn-secondary btn-block">Block level button</button>
C
codecalm 已提交
131 132
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
133 134 135 136 137

### Button with icon

Basic buttons are traditional buttons with borders and background with an extra commponent like an icon. You can place it either on the left or the right which ever you want with different color opitons.

C
codecalm 已提交
138
Icons can be found [**here**](/docs/icons.html#icons)
D
Dawid Harat 已提交
139

C
codecalm 已提交
140
{% capture code %}
D
Dawid Harat 已提交
141
<button type="button" class="btn btn-dark">
C
codecalm 已提交
142
{% include ui/icon.html icon="upload" %}
D
Dawid Harat 已提交
143 144 145
Upload
</button>
<button type="button" class="btn btn-warning">
C
codecalm 已提交
146
{% include ui/icon.html icon="heart" %}
D
Dawid Harat 已提交
147 148 149
I like
</button>
<button type="button" class="btn btn-success">
C
codecalm 已提交
150
{% include ui/icon.html icon="check" %}
D
Dawid Harat 已提交
151 152 153
I agree
</button>
<button type="button" class="btn btn-outline-primary">
C
codecalm 已提交
154
{% include ui/icon.html icon="plus" %}
D
Dawid Harat 已提交
155 156 157
More
</button>
<button type="button" class="btn btn-danger">
C
codecalm 已提交
158
{% include ui/icon.html icon="link" %}
D
Dawid Harat 已提交
159 160 161
Link
</button>
<button type="button" class="btn btn-info">
C
codecalm 已提交
162
{% include ui/icon.html icon="message-circle" %}
D
Dawid Harat 已提交
163 164
Comment
</button>
C
codecalm 已提交
165 166
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
167 168 169

### Social buttons

C
codecalm 已提交
170 171
A button can be formatted to link to a social website

C
codecalm 已提交
172
{% capture code %}
173
{% for button in site.socials %}
D
Dawid Harat 已提交
174 175 176
{% assign btn-icon = button[1].icon %}
{% assign btn-title = button[1].title %}
{% assign btn-color = button[0] %}
C
codecalm 已提交
177
{% include ui/button.html color=btn-color icon=btn-icon text=btn-title %}
178
{% endfor %}
C
codecalm 已提交
179 180
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
181 182 183

You can use only icons.

C
codecalm 已提交
184
{% capture code %}
185
{% for button in site.socials %}
D
Dawid Harat 已提交
186 187
{% assign btn-icon = button[1].icon %}
{% assign btn-color = button[0] %}
C
codecalm 已提交
188
{% include ui/button.html color=btn-color icon=btn-icon icon-only=true %}
189
{% endfor %}
C
codecalm 已提交
190 191
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
192 193 194 195 196

### Icon buttons

Icon only button. Add `.btn-icon` class to remove unnecessary padding from button.

C
codecalm 已提交
197 198 199 200 201 202 203 204 205
{% capture code %}
{% include ui/button.html icon="activity" color="primary" icon-only=true %}
{% include ui/button.html icon="github" color="github" icon-only=true %}
{% include ui/button.html icon="bell" color="success" icon-only=true %}
{% include ui/button.html icon="star" color="warning" icon-only=true %}
{% include ui/button.html icon="trash-2" color="danger" icon-only=true %}
{% include ui/button.html icon="bar-chart" color="purple" icon-only=true %}
{% include ui/button.html icon="git-merge" color="secondary" icon-only=true %}
{% endcapture %}
C
codecalm 已提交
206
{% include example.html code=code wrapper="btn-list" centered=true %}
C
codecalm 已提交
207

208 209 210 211

### Button dropdown

Wrap the dropdown’s toggle (your button or link) and the dropdown menu within `.dropdown`, or another element that declares `position: relative;`. Dropdowns can be triggered from `<a>` or `<button>` elements to better fit your potential needs.
C
chomik 已提交
212

C
codecalm 已提交
213
{% capture code %}
214 215
<div class="dropdown">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">
C
codecalm 已提交
216
     {% include ui/icon.html icon="calendar" %}
217
  </button>
C
codecalm 已提交
218
  {% include ui/dropdown-menu.html %}
219 220 221 222
</div>

<div class="dropdown">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">
C
codecalm 已提交
223
     {% include ui/icon.html icon="calendar" %}Show calendar
224
  </button>
C
codecalm 已提交
225
  {% include ui/dropdown-menu.html %}
226 227 228 229 230 231
</div>

<div class="dropdown">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">
     Show calendar
  </button>
C
codecalm 已提交
232
  {% include ui/dropdown-menu.html %}
233
</div>
C
codecalm 已提交
234
{% endcapture %}
C
codecalm 已提交
235
{% include example.html code=code wrapper="btn-list" centered=true %}
236 237 238 239 240

### Loading button

Add `.btn-loading` to use a loading state on a button. The width of the button depends on the length of the text inside.

C
codecalm 已提交
241 242 243 244 245 246 247 248

{% capture code %}
{% include ui/button.html color="primary" text="Button" loading=true %}
{% include ui/button.html color="primary" text="Loading button with loooong content" loading=true %}
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}


249

C
codecalm 已提交
250
{% capture code %}
C
codecalm 已提交
251
{% include ui/button.html color="primary" text="Button" spinner=true %}
C
codecalm 已提交
252
{% endcapture %}
C
codecalm 已提交
253
{% include example.html code=code centered=true %}
254 255 256 257 258

### List of buttons

You can now create a list of buttons with the `.btn-list` container.

C
codecalm 已提交
259
{% capture code %}
260
<div class="btn-list">
C
codecalm 已提交
261 262 263
  <a href="#" class="btn btn-success">Save changes</a>
  <a href="#" class="btn btn-secondary">Save and continue</a>
  <a href="#" class="btn btn-danger">Cancel</a>
264
</div>
C
codecalm 已提交
265
{% endcapture %}
C
codecalm 已提交
266
{% include example.html code=code centered=true %}
267 268 269

If the list is very long, it will automatically wrap on multiple lines, while keeping all buttons evenly spaced.

C
codecalm 已提交
270
{% capture code %}
271
<div class="btn-list">
C
codecalm 已提交
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
  <a href="#" class="btn btn-secondary">One</a>
  <a href="#" class="btn btn-secondary">Two</a>
  <a href="#" class="btn btn-secondary">Three</a>
  <a href="#" class="btn btn-secondary">Four</a>
  <a href="#" class="btn btn-secondary">Five</a>
  <a href="#" class="btn btn-secondary">Six</a>
  <a href="#" class="btn btn-secondary">Seven</a>
  <a href="#" class="btn btn-secondary">Eight</a>
  <a href="#" class="btn btn-secondary">Nine</a>
  <a href="#" class="btn btn-secondary">Ten</a>
  <a href="#" class="btn btn-secondary">Eleven</a>
  <a href="#" class="btn btn-secondary">Twelve</a>
  <a href="#" class="btn btn-secondary">Thirteen</a>
  <a href="#" class="btn btn-secondary">Fourteen</a>
  <a href="#" class="btn btn-secondary">Fifteen</a>
  <a href="#" class="btn btn-secondary">Sixteen</a>
  <a href="#" class="btn btn-secondary">Seventeen</a>
  <a href="#" class="btn btn-secondary">Eighteen</a>
  <a href="#" class="btn btn-secondary">Nineteen</a>
291
</div>
C
codecalm 已提交
292 293
{% endcapture %}
{% include example.html code=code %}
294 295 296

Use the `.text-center` or the `.text-right` modifiers to alter the alignment.

C
codecalm 已提交
297
{% capture code %}
C
codecalm 已提交
298
<div class="btn-list justify-content-center">
C
codecalm 已提交
299
  <a href="#" class="btn btn-secondary">Save and continue</a>
C
codecalm 已提交
300
  <a href="#" class="btn btn-primary">Save changes</a>
301
</div>
C
codecalm 已提交
302 303
{% endcapture %}
{% include example.html code=code %}
304

C
codecalm 已提交
305
{% capture code %}
C
codecalm 已提交
306 307
<div class="btn-list justify-content-end">
  <a href="#" class="btn btn-secondary">Save and continue</a>
C
codecalm 已提交
308
  <a href="#" class="btn btn-primary">Save changes</a>
C
codecalm 已提交
309 310 311 312 313 314 315
</div>
{% endcapture %}
{% include example.html code=code %}

{% capture code %}
<div class="btn-list">
  <a href="#" class="btn btn-outline-danger mr-auto">Delete</a>
C
codecalm 已提交
316
  <a href="#" class="btn btn-secondary">Save and continue</a>
C
codecalm 已提交
317
  <a href="#" class="btn btn-primary">Save changes</a>
318
</div>
C
codecalm 已提交
319 320
{% endcapture %}
{% include example.html code=code %}
M
mrszympek 已提交
321 322 323

### Button with avatar

C
codecalm 已提交
324
{% capture code %}
C
codecalm 已提交
325
<a href="#" class="btn btn-secondary">
C
codecalm 已提交
326
  {% include ui/avatar.html person-id="4" %} Avatar
C
codecalm 已提交
327 328
</a>
<a href="#" class="btn btn-secondary">
C
codecalm 已提交
329
  {% include ui/avatar.html person-id="5" %} Avatar
C
codecalm 已提交
330 331
</a>
<a href="#" class="btn btn-secondary">
C
codecalm 已提交
332
  {% include ui/avatar.html person-id="6" %} Avatar
C
codecalm 已提交
333
</a>
C
codecalm 已提交
334
{% endcapture %}
C
codecalm 已提交
335
{% include example.html code=code wrapper="btn-list" centered=true %}