Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 按钮


按钮样式

Bootstrap 提供了不同样式的按钮

为了实现以上按钮样式,Bootstrap 有以下类

  • .btn
  • .btn-default
  • .btn-primary
  • .btn-success
  • .btn-info
  • .btn-warning
  • .btn-danger
  • .btn-link

以下示例展示了不同按钮样式的代码

示例

<button type="button" class="btn">基础</button>
<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>
自己试一试 »

按钮类可以用于 <a>, <button>, 或 <input> 元素

示例

<a href="#" class="btn btn-info" role="button">链接按钮</a>
<button type="button" class="btn btn-info">按钮</button>
<input type="button" class="btn btn-info" value="输入按钮">
<input type="submit" class="btn btn-info" value="提交按钮">
自己试一试 »

为什么我们在链接的 href 属性中加 #?

因为我们没有要链接到的页面,并且我们不想得到 "404" 错误信息,我们在我们的示例中使用 # 作为链接。它应该是一个指向特定页面的真实 URL。



按钮大小

Bootstrap 提供了四种按钮大小

定义不同大小的类是

  • .btn-lg
  • .btn-sm
  • .btn-xs

以下示例展示了不同按钮大小的代码

示例

<button type="button" class="btn btn-primary btn-lg">大</button>
<button type="button" class="btn btn-primary">普通</button>
<button type="button" class="btn btn-primary btn-sm">小</button>
<button type="button" class="btn btn-primary btn-xs">超小</button>
自己试一试 »

块级按钮

块级按钮跨越父元素的整个宽度。

添加类 .btn-block 来创建一个块级按钮

示例

<button type="button" class="btn btn-primary btn-block">按钮 1</button>
自己试一试 »

激活/禁用按钮

按钮可以设置为激活(看起来按下)或禁用(不可点击)状态

.active 使按钮看起来按下,而类 .disabled 使按钮不可点击

示例

<button type="button" class="btn btn-primary active">激活主要</button>
<button type="button" class="btn btn-primary disabled">禁用主要</button>
自己试一试 »

用练习测试自己

练习

添加 Bootstrap 类来正确地将按钮样式化为 "危险" 按钮。

<button class="">Danger</button>

开始练习


完整 Bootstrap 按钮参考

有关所有按钮类的完整参考,请访问我们的完整 Bootstrap 按钮参考


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.