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


按钮样式

Bootstrap 5 提供了不同样式的按钮

示例

<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-success">链接按钮</a>
<button type="button" class="btn btn-success">按钮</button>
<input type="button" class="btn btn-success" value="输入按钮">
<input type="submit" class="btn btn-success" value="提交按钮">
<input type="reset" class="btn btn-success" value="重置按钮">
亲自试一试 »

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

因为我们没有要链接的页面,并且我们不想收到“404”错误,所以我们使用 # 作为链接。在现实生活中,它应该当然是一个指向“搜索”页面的真实 URL。


按钮边框

Bootstrap 5 还提供了八种边框/轮廓按钮。

将鼠标移到它们上面,可以查看额外的“悬停”效果

示例

<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>
亲自试一试 »

块级按钮

要创建一个跨越父元素整个宽度的块级按钮,请在父元素上使用 .d-grid “辅助”类

示例

<div class="d-grid">
  <button type="button" class="btn btn-primary btn-block">全宽按钮</button>
</div>
亲自试一试 »

如果你有很多块级按钮,可以使用 .gap-* 类控制它们之间的间距

示例

<div class="d-grid gap-3">
  <button type="button" class="btn btn-primary btn-block">全宽按钮</button>
  <button type="button" class="btn btn-primary btn-block">全宽按钮</button>
  <button type="button" class="btn btn-primary btn-block">全宽按钮</button>
</div>
亲自试一试 »

激活/禁用按钮

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

.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>
亲自试一试 »

加载器按钮

你也可以在按钮中添加“加载器”,你将在我们的 BS5 加载器教程 中了解更多关于加载器的知识

示例

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