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:

ClassDescriptionInstance
.btnAdd basic for button StyleTry it
.btn-defaultDefault/Standard buttonTry it
.btn-primaryOriginal button style (not operated)Try it
.btn-success Indicates successful actionTry it
.btn-infoThis style can be used for buttons that want to pop up informationTry it
.btn-warningButton indicating the need to operate with cautionTry it
.btn-dangerA button operation indicating a dangerous actionTry it
.btn-linkLet The button looks like a link (still retaining the button behavior)Try it
.btn-lgMake a big buttonTry it
.btn-smMake a small buttonTry it
.btn-xsMake a super small buttonTry it
.btn-blockBlock level button (pull Extend to 100% of the width of the parent element)Try it
.activeThe button is clickedTry it
.disabledDisable buttonTry 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:

ClassDescription
.btn-lgThis will make the button look larger .
.btn-smThis will make the button look smaller.
.btn-xsThis will make the button look extremely small.
.btn-blockThis 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:

ElementsClass
Button elementAdd .active class to show that it is active.
Anchor elementAdd .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


##Disabled status

When you disable a button , its color will become 50% lighter and lose its gradient.

The following table lists the classes that make button elements and anchor elements disabled:

ElementsClassButton ElementAdd Anchor elementAdd
disabled Attribute to the <button> button.
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.


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-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

Button label

You can use the <a>, <button> or <input> element Use the button class on it. However, it is recommended that you use the button class on the <button> element to avoid cross-browser inconsistencies.

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>

<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