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 4 按钮


按钮样式

Bootstrap 4 提供不同样式的按钮

示例

<button type="button" class="btn">基本</button>
<button type="button" class="btn btn-primary">主要</button>
<button type="button" class="btn btn-secondary">次要</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-dark">深色</button>
<button type="button" class="btn btn-light">浅色</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 4 提供八种轮廓/带边框按钮

示例

<button type="button" class="btn btn-outline-primary">主要</button>
<button type="button" class="btn btn-outline-secondary">次要</button>
<button type="button" class="btn btn-outline-success">成功</button>
<button type="button" class="btn btn-outline-info">信息</button>
<button type="button" class="btn btn-outline-warning">警告</button>
<button type="button" class="btn btn-outline-danger">危险</button>
<button type="button" class="btn btn-outline-dark">深色</button>
<button type="button" class="btn btn-outline-light text-dark">浅色</button>
自己尝试 »


按钮尺寸

使用 .btn-lg 类创建大型按钮或使用 .btn-sm 类创建小型按钮

示例

<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>
自己尝试 »

块级按钮

添加类 .btn-block 创建一个块级按钮,它会跨越父元素的整个宽度。

示例

<button type="button" class="btn btn-primary btn-block">全宽按钮</button>
自己尝试 »

活动/禁用按钮

按钮可以设置为活动状态(显示为按下)或禁用状态(不可点击)

.active 使按钮显示为按下,属性 disabled 使按钮不可点击。请注意,<a> 元素不支持 disabled 属性,因此必须使用 .disabled 类来使其在视觉上显示为禁用。

示例

<button type="button" class="btn btn-primary active">活动主要</button>
<button type="button" class="btn btn-primary" disabled>禁用主要</button>
<a href="#" class="btn btn-primary disabled">禁用链接</a>
自己尝试 »

加载动画按钮

您还可以向按钮添加 "加载动画",您将在我们的 BS4 加载动画教程 中了解更多信息

示例

<button class="btn btn-primary">
  <span class="spinner-border spinner-border-sm"></span>
</button>

<button class="btn btn-primary">
  <span class="spinner-border spinner-border-sm"></span>
  加载中..
</button>

<button class="btn btn-primary" disabled>
  <span class="spinner-border spinner-border-sm"></span>
  加载中..
</button>

<button class="btn btn-primary" disabled>
  <span class="spinner-grow spinner-grow-sm"></span>
  加载中..
</button>
自己尝试 »

×

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.