buttons.md 13.3 KB
Newer Older
C
chomik 已提交
1 2
---
title: Buttons
M
Martyna 已提交
3
description: Use button styles that best suit your designs and encourage users to take the desired actions. You can customize the button's properties to improve the user experience of your website or system, changing the size, shape, color and many more.
C
codecalm 已提交
4
bootstrap-link: components/buttons/
C
codecalm 已提交
5
done: true
C
codecalm 已提交
6
libs: tabler-buttons
C
chomik 已提交
7 8
---

C
codecalm 已提交
9

C
codecalm 已提交
10
## Button tag
11

M
Martyna 已提交
12
As one of the most common elements of UI design, buttons have a very important function of engaging users with your website or app and guiding them in their actions. Use the `.btn` classes with the `<button>` element and add additional styling that will make your buttons serve their purpose and draw users' attention. 
13

C
codecalm 已提交
14
{% capture code %}
C
codecalm 已提交
15
<a href="#" class="btn btn-primary" role="button">Link</a>
16
<button class="btn btn-primary">Button</button>
C
codecalm 已提交
17 18 19
<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 已提交
20 21 22
{% endcapture  %}
{% include example.html code=code wrapper="btn-list" centered=true %}

23

C
codecalm 已提交
24
## Button variations
25

M
Martyna 已提交
26
Use the button classes that correspond to the function of your button. The big range of available colors will help you show your buttons' purpose and make them easy to spot.
27

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

C
codecalm 已提交
37

C
codecalm 已提交
38
## Disabled buttons
39

M
buttons  
Martyna 已提交
40
Make buttons look inactive to show that an action is possible once the user meets certain criteria, such as completing the required fields to submit a form. 
D
Dawid Harat 已提交
41

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

C
codecalm 已提交
51

M
Martyna 已提交
52
## Color variations
53

M
Martyna 已提交
54
Choose the right color for your button to make it go well with your design and draw users' attention. Button colors can have a big influence on users' decisions, which is why it's important to choose them based on the intended purpose.
55

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

C
codecalm 已提交
63

M
buttons  
Martyna 已提交
64
## Ghost buttons
C
codecalm 已提交
65

M
buttons  
Martyna 已提交
66
Use the `.btn-ghost-*` class to make your button look simple yet aesthetically appealing. Ghost buttons help focus users' attention on the website's primary design, at the same time encouraging them to take action. 
C
codecalm 已提交
67 68 69 70 71 72 73

{% 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 %}
74

C
codecalm 已提交
75

C
codecalm 已提交
76
## Square buttons
77

M
Martyna 已提交
78
Use the `.btn-square` class to remove the border radius, if you want the corners of your button to be square rather than rounded.
79

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

C
codecalm 已提交
89

C
codecalm 已提交
90
## Pill buttons
91

M
buttons  
Martyna 已提交
92
Add the `.btn-pill` class to your button to make it rounded and give it a modern and attractive look.
93

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

C
codecalm 已提交
103

C
codecalm 已提交
104
## Outline buttons
105

M
Martyna 已提交
106
Replace the default modifier class with the `.btn-outline-*` class, if you want to remove the color and the background of your button and give it a more subtle look. Outline buttons are perfect to use as secondary buttons, as they don't distract users from the main action.
107

C
codecalm 已提交
108
{% capture code %}
C
codecalm 已提交
109
{% for button in site.button-variants %}
D
Dawid Harat 已提交
110 111
{% assign btn-color = button[1].class %}
{% assign btn-title = button[1].title %}
C
codecalm 已提交
112
{% include ui/button.html text=btn-title color=btn-color outline=true %}
M
mrszympek 已提交
113
{% endfor %}
C
codecalm 已提交
114 115
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
M
mrszympek 已提交
116

C
codecalm 已提交
117

C
codecalm 已提交
118
## Button size
119

M
buttons  
Martyna 已提交
120
Add `.btn-lg` or `.btn-sm` to change the size of your button and differentiate those which should have primary focus from those of secondary importance. Adapt the button size to your design and encourage users to take actions.  
121

C
codecalm 已提交
122
{% capture code %}
123 124
<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 已提交
125 126
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
127

C
codecalm 已提交
128
{% capture code %}
129 130
<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 已提交
131 132
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
133

M
buttons  
Martyna 已提交
134
You can also add the `.btn-block` class to create block level buttons which span the full width of a parent.
135

C
codecalm 已提交
136
{% capture code %}
137 138
<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 已提交
139 140
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
141

C
codecalm 已提交
142

M
buttons  
Martyna 已提交
143
## Buttons with icons
144

M
Martyna 已提交
145
Label your button with text and add an icon to communiacate the action and make it easy to identify for users. Icons are easily recognized and improve the aesthetics of your button design, giving it a modern and atractive look.  
146

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

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

C
codecalm 已提交
177

C
codecalm 已提交
178
## Social buttons
179

M
buttons  
Martyna 已提交
180
You can use the icons of popular social networking sites, which users are familiar with. Thanks to buttons with social media icons users can share content or follow a website with just one click, without leaving the website.
C
codecalm 已提交
181

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

M
buttons  
Martyna 已提交
192
You can also add an icon without the name of a social networking site, if you want to display more buttons on a small space.
193

C
codecalm 已提交
194
{% capture code %}
195
{% for button in site.socials %}
D
Dawid Harat 已提交
196 197
{% assign btn-icon = button[1].icon %}
{% assign btn-color = button[0] %}
C
codecalm 已提交
198
{% include ui/button.html color=btn-color icon=btn-icon icon-only=true %}
199
{% endfor %}
C
codecalm 已提交
200 201
{% endcapture %}
{% include example.html code=code wrapper="btn-list" centered=true %}
202

C
codecalm 已提交
203

C
codecalm 已提交
204
## Icon buttons
205

M
Martyna 已提交
206
Add the `.btn-icon` class to remove unnecessary padding from your button and use an icon without any additional label. Thanks to that, you can save space and make the action easy to recognize for international users.
207

C
codecalm 已提交
208 209
{% capture code %}
{% include ui/button.html icon="activity" color="primary" icon-only=true %}
210
{% include ui/button.html icon="brand/github" color="github" icon-only=true %}
C
codecalm 已提交
211 212
{% include ui/button.html icon="bell" color="success" icon-only=true %}
{% include ui/button.html icon="star" color="warning" icon-only=true %}
213 214
{% include ui/button.html icon="trash" color="danger" icon-only=true %}
{% include ui/button.html icon="chart-bar" color="purple" icon-only=true %}
C
codecalm 已提交
215 216
{% include ui/button.html icon="git-merge" color="secondary" icon-only=true %}
{% endcapture %}
C
codecalm 已提交
217
{% include example.html code=code wrapper="btn-list" centered=true %}
C
codecalm 已提交
218

219

M
buttons  
Martyna 已提交
220
## Dropdown buttons
221

M
buttons  
Martyna 已提交
222
Create a dropdown button that will encourage users to click for more options. You can add a label with an icon or remove the label and add an icon on its own if you want to save space. Choose the option that will best suit your design and improve the user experience. 
C
chomik 已提交
223

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

<div class="dropdown">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">
C
codecalm 已提交
234
     {% include ui/icon.html icon="calendar" %}Show calendar
235
  </button>
C
codecalm 已提交
236
  {% include ui/dropdown-menu.html %}
237 238 239 240 241 242
</div>

<div class="dropdown">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown">
     Show calendar
  </button>
C
codecalm 已提交
243
  {% include ui/dropdown-menu.html %}
244
</div>
C
codecalm 已提交
245
{% endcapture %}
C
codecalm 已提交
246
{% include example.html code=code wrapper="btn-list" centered=true %}
247

C
codecalm 已提交
248

M
buttons  
Martyna 已提交
249
## Loading buttons
250

M
buttons  
Martyna 已提交
251
Add the `.btn-loading` class to show a button's loading state, which can be useful in the case of operations that take longer to process. Thanks to that, users will be aware of the current state of their action and won't give it up before it's finished.
252

C
codecalm 已提交
253 254 255 256 257 258 259 260

{% 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 %}


261

C
codecalm 已提交
262
{% capture code %}
C
codecalm 已提交
263
{% include ui/button.html color="primary" text="Button" spinner=true %}
C
codecalm 已提交
264
{% endcapture %}
C
codecalm 已提交
265
{% include example.html code=code centered=true %}
266

C
codecalm 已提交
267

C
codecalm 已提交
268
## List of buttons
269

M
buttons  
Martyna 已提交
270
Create a list of buttons using the `.btn-list` container to display different actions a user can take. If you add aditional styling, such as colours, you will be able to focus users' attention on a particular action or suggest the result. 
271

C
codecalm 已提交
272
{% capture code %}
273
<div class="btn-list">
C
codecalm 已提交
274 275 276
  <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>
277
</div>
C
codecalm 已提交
278
{% endcapture %}
C
codecalm 已提交
279
{% include example.html code=code %}
280

M
buttons  
Martyna 已提交
281
If the list is long, it will be wrapped and some buttons will be moved to the next line, keeping them all evenly spaced.
282

C
codecalm 已提交
283
{% capture code %}
284
<div class="btn-list">
C
codecalm 已提交
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
  <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>
304
</div>
C
codecalm 已提交
305 306
{% endcapture %}
{% include example.html code=code %}
307

M
buttons  
Martyna 已提交
308
Use the `.text-center` or the `.text-right` modifiers to change the buttons' alignment and place them where they suit best.
309

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

C
codecalm 已提交
318
{% capture code %}
C
codecalm 已提交
319 320
<div class="btn-list justify-content-end">
  <a href="#" class="btn btn-secondary">Save and continue</a>
C
codecalm 已提交
321
  <a href="#" class="btn btn-primary">Save changes</a>
C
codecalm 已提交
322 323 324 325 326 327 328
</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 已提交
329
  <a href="#" class="btn btn-secondary">Save and continue</a>
C
codecalm 已提交
330
  <a href="#" class="btn btn-primary">Save changes</a>
331
</div>
C
codecalm 已提交
332 333
{% endcapture %}
{% include example.html code=code %}
M
mrszympek 已提交
334

C
codecalm 已提交
335

M
buttons  
Martyna 已提交
336 337
## Buttons with avatars

M
Martyna 已提交
338
Use buttons with avatars to simplify the process of interaction and make your design more personalized. Buttons can contain avatars and labels or only avatars, if displayed on a smaller space. 
M
mrszympek 已提交
339

C
codecalm 已提交
340
{% capture code %}
C
codecalm 已提交
341
<a href="#" class="btn btn-secondary">
C
codecalm 已提交
342
  {% include ui/avatar.html person-id="4" %} Avatar
C
codecalm 已提交
343 344
</a>
<a href="#" class="btn btn-secondary">
C
codecalm 已提交
345
  {% include ui/avatar.html person-id="5" %} Avatar
C
codecalm 已提交
346 347
</a>
<a href="#" class="btn btn-secondary">
C
codecalm 已提交
348
  {% include ui/avatar.html person-id="6" %} Avatar
C
codecalm 已提交
349
</a>
C
codecalm 已提交
350
{% endcapture %}
C
codecalm 已提交
351
{% include example.html code=code wrapper="btn-list" centered=true %}