Bootstrap button
This chapter will explain how to use Bootstrap buttons through examples. Any element with class .btn will inherit the default appearance of a rounded gray button. However, Bootstrap provides some options to define the style of buttons, as shown in the following table:
The following styles can be used on <a>, <button>, or <input> elements:
Class | Description | Instance |
---|---|---|
.btn | Add basic for button Style | Try it |
.btn-default | Default/Standard button | Try it |
.btn-primary | Original button style (not operated) | Try it |
.btn-success | Indicates successful action | Try it |
.btn-info | This style can be used for buttons that want to pop up information | Try it |
.btn-warning | Button indicating the need to operate with caution | Try it |
.btn-danger | A button operation indicating a dangerous action | Try it |
.btn-link | Let The button looks like a link (still retaining the button behavior) | Try it |
.btn-lg | Make a big button | Try it |
.btn-sm | Make a small button | Try it |
.btn-xs | Make a super small button | Try it |
.btn-block | Block level button (pull Extend to 100% of the width of the parent element) | Try it |
.active | The button is clicked | Try it |
.disabled | Disable button | Try it |
The following example demonstrates all of the above Button class:
Instance
<!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 按钮选项</title> <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css"> <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script> </head> <body> <!-- 标准的按钮 --> <button type="button" class="btn btn-default">默认按钮</button> <!-- 提供额外的视觉效果,标识一组按钮中的原始动作 --> <button type="button" class="btn btn-primary">原始按钮</button> <!-- 表示一个成功的或积极的动作 --> <button type="button" class="btn btn-success">成功按钮</button> <!-- 信息警告消息的上下文按钮 --> <button type="button" class="btn btn-info">信息按钮</button> <!-- 表示应谨慎采取的动作 --> <button type="button" class="btn btn-warning">警告按钮</button> <!-- 表示一个危险的或潜在的负面动作 --> <button type="button" class="btn btn-danger">危险按钮</button> <!-- 并不强调是一个按钮,看起来像一个链接,但同时保持按钮的行为 --> <button type="button" class="btn btn-link">链接按钮</button> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
Button size
The following table lists the classes for obtaining buttons of various sizes:
Class | Description |
---|---|
.btn-lg | This will make the button look larger . |
.btn-sm | This will make the button look smaller. |
.btn-xs | This will make the button look extremely small. |
.btn-block | This will create a block-level button that spans the full width of the parent element. |
The following example demonstrates all the above button classes:
Instance
<!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 按钮大小</title> <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css"> <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script> </head> <body> <p> <button type="button" class="btn btn-primary btn-lg"> 大的原始按钮 </button> <button type="button" class="btn btn-default btn-lg"> 大的按钮 </button> </p> <p> <button type="button" class="btn btn-primary"> 默认大小的原始按钮 </button> <button type="button" class="btn btn-default"> 默认大小的按钮 </button> </p> <p> <button type="button" class="btn btn-primary btn-sm"> 小的原始按钮 </button> <button type="button" class="btn btn-default btn-sm"> 小的按钮 </button> </p> <p> <button type="button" class="btn btn-primary btn-xs"> 特别小的原始按钮 </button> <button type="button" class="btn btn-default btn-xs"> 特别小的按钮 </button> </p> <p> <button type="button" class="btn btn-primary btn-lg btn-block"> 块级的原始按钮 </button> <button type="button" class="btn btn-default btn-lg btn-block"> 块级的按钮 </button> </p> </body> </html>
Run Example»
Click the "Run Instance" button to view the online instance
Button status
Bootstrap provides classes for activation, deactivation and other button states, which will be explained in detail below.
Activation state
The button will have a pressed appearance (dark background, dark border, shadow) when activated.
The following table lists the classes that make button elements and anchor elements active:
Elements | Class |
---|---|
Button element | Add .active class to show that it is active. |
Anchor element | Add .active class to the <a> button to show that it is active. |
The following example demonstrates this:
Example
<!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 按钮激活状态</title> <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css"> <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script> </head> <body> <p> <button type="button" class="btn btn-default btn-lg "> 默认按钮 </button> <button type="button" class="btn btn-default btn-lg active"> 激活按钮 </button> </p> <p> <button type="button" class="btn btn-primary btn-lg "> 原始按钮 </button> <button type="button" class="btn btn-primary btn-lg active"> 激活的原始按钮 </button> </p> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Class | |
---|---|
Add | disabled Attribute to the <button> button. |
Add | disabled class to the <a> button. Note: This class will only change the appearance of <a>, but will not change its functionality. Here you need to use custom JavaScript to disable the link. |
下面的实例演示了这点: <!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 按钮禁用状态</title> <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css"> <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script> </head> <body> <p> <button type="button" class="btn btn-default btn-lg"> 默认按钮 </button> <button type="button" class="btn btn-default btn-lg" disabled="disabled"> 禁用按钮 </button> </p> <p> <button type="button" class="btn btn-primary btn-lg "> 原始按钮 </button> <button type="button" class="btn btn-primary btn-lg" disabled="disabled"> 禁用的原始按钮 </button> </p> <p> <a href="#" class="btn btn-default btn-lg" role="button"> 链接 </a> <a href="#" class="btn btn-default btn-lg disabled" role="button"> 禁用链接 </a> </p> <p> <a href="#" class="btn btn-primary btn-lg" role="button"> 原始链接 </a> <a href="#" class="btn btn-primary btn-lg disabled" role="button"> 禁用的原始链接 </a> </p> </body> </html>
Run Instance » Click the "Run Instance" button to view the online instance
<!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 按钮标签</title> <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css"> <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script> </head> <body> <a class="btn btn-default" href="#" role="button">链接</a> <button class="btn btn-default" type="submit">按钮</button> <input class="btn btn-default" type="button" value="输入"> <input class="btn btn-default" type="submit" value="提交"> </body> </html>
Run Example»Click "Run instance" button to view online instances