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


徽章

徽章用于为任何内容添加更多信息

示例标题

示例标题

示例标题

示例标题

示例标题
示例标题

.badge 类与上下文类(如 .bg-secondary)一起使用,放在 <span> 元素中,创建矩形徽章。请注意,徽章会按比例缩放以匹配父元素(如果有)的大小

示例

<h1>示例标题 <span class="badge bg-secondary">新</span></h1>
<h2>示例标题 <span class="badge bg-secondary">新</span></h2>
<h3>示例标题 <span class="badge bg-secondary">新</span></h3>
<h4>示例标题 <span class="badge bg-secondary">新</span></h4>
<h5>示例标题 <span class="badge bg-secondary">新</span></h5>
<h6>示例标题 <span class="badge bg-secondary">新</span></h6>
亲自试一试 »

上下文徽章

主要 次要 成功 危险 警告 信息 浅色 深色

使用任何上下文类 (.bg-*) 更改徽章的颜色

示例

<span class="badge bg-primary">主要</span>
<span class="badge bg-secondary">次要</span>
<span class="badge bg-success">成功</span>
<span class="badge bg-danger">危险</span>
<span class="badge bg-warning">警告</span>
<span class="badge bg-info">信息</span>
<span class="badge bg-light">浅色</span>
<span class="badge bg-dark">深色</span>
亲自试一试 »


药丸徽章

主要 次要 成功 危险 警告 信息 浅色 深色

使用 .rounded-pill 类使徽章更圆

示例

<span class="badge rounded-pill bg-primary">主要</span>
<span class="badge rounded-pill bg-secondary">次要</span>
<span class="badge rounded-pill bg-success">成功</span>
<span class="badge rounded-pill bg-danger">危险</span>
<span class="badge rounded-pill bg-warning">警告</span>
<span class="badge rounded-pill bg-info">信息</span>
<span class="badge rounded-pill bg-light">浅色</span>
<span class="badge rounded-pill bg-dark">深色</span>
亲自试一试 »

元素内的徽章

在按钮内使用徽章的示例

示例

<button type="button" class="btn btn-primary">
  消息 <span class="badge bg-danger">4</span>
</button>
亲自试一试 »

你知道吗?

W3.CSS 是 Bootstrap 5 的绝佳替代方案。

W3.CSS 更小、更快、更易于使用。

如果您想学习 W3.CSS,请访问我们的 W3.CSS 教程


×

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.