小白教程
所有教程
关于
Search
172.70.126.66
172.70.126.66
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Bootstrap5 徽章(Badges)”的源代码
本页内容
上一节:
Bootstrap5_按钮组
下一节:
Bootstrap5_进度条
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:Bootstrap5 徽章}}[[Category:Bootstrap 5 教程|13]] = Bootstrap5 徽章(Badges) = 徽章(Badges)主要用于突出显示新的或未读的项。如需使用徽章,只需要将 .badge 类加上带有指定意义的颜色类 (如 .bg-secondary) 添加到 <span> 元素上即可。 徽章可以根据父元素的大小的变化而变化: <sample title="" desc="" lang="html" hererun="1"> <h1>测试标题 <span class="badge bg-secondary">New</span></h1> <h2>测试标题 <span class="badge bg-secondary">New</span></h2> <h3>测试标题 <span class="badge bg-secondary">New</span></h3> <h4>测试标题 <span class="badge bg-secondary">New</span></h4> <h5>测试标题 <span class="badge bg-secondary">New</span></h5> <h6>测试标题 <span class="badge bg-secondary">New</span></h6> </sample> <run name=""> <!DOCTYPE html> <html> <head> <title>Bootstrap5 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script> </head> <body> <div class="container mt-3"> <h2>徽章</h2> <h1>测试标题 <span class="badge bg-secondary">New</span></h1> <h2>测试标题 <span class="badge bg-secondary">New</span></h2> <h3>测试标题 <span class="badge bg-secondary">New</span></h3> <h4>测试标题 <span class="badge bg-secondary">New</span></h4> <h5>测试标题 <span class="badge bg-secondary">New</span></h5> <h6>测试标题 <span class="badge bg-secondary">New</span></h6> </div> </body> </html> </run> == 各种颜色类型的徽章 == 以下列出了所有颜色类型的徽章: <sample title="" desc="" lang="html" hererun="1"> <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> </sample> <run name=""> <!DOCTYPE html> <html> <head> <title>Bootstrap5 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script> </head> <body> <div class="container mt-3"> <h2>各种颜色类型的徽章</h2> <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> </div> </body> </html> </run> == 药丸形状徽章 == 使用 .rounded-pill 类来设置药丸形状徽章: <sample title="" desc="" lang="html" hererun="1"> <span class="badge rounded-pill bg-default">默认</span> <span class="badge rounded-pill bg-primary">主要</span> <span class="badge rounded-pill bg-success">成功</span> <span class="badge rounded-pill bg-info">信息</span> <span class="badge rounded-pill bg-warning">警告</span> <span class="badge rounded-pill bg-danger">危险</span> </sample> <run name=""> <!DOCTYPE html> <html> <head> <title>Bootstrap5 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script> </head> <body> <div class="container mt-3"> <h2>药丸形状徽章</h2> <span class="badge rounded-pill bg-default">默认</span> <span class="badge rounded-pill bg-primary">主要</span> <span class="badge rounded-pill bg-success">成功</span> <span class="badge rounded-pill bg-info">信息</span> <span class="badge rounded-pill bg-warning">警告</span> <span class="badge rounded-pill bg-danger">危险</span> </div> </body> </html> </run> == 徽章插入到元素内 == 以下实例将徽章嵌入到按钮内: <sample title="" desc="" lang="html" hererun="1"> <button type="button" class="btn btn-primary"> Messages <span class="badge bg-light">4</span> </button> </sample> <run name=""> <!DOCTYPE html> <html> <head> <title>Bootstrap5 实例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script> </head> <body> <div class="container mt-3"> <h2>徽章嵌入到按钮内</h2> <button type="button" class="btn btn-primary"> Messages <span class="badge bg-danger">4</span> </button> <button type="button" class="btn btn-danger"> Notifications <span class="badge bg-dark">7</span> </button> </div> </body> </html> </run>
返回至“
Bootstrap5 徽章(Badges)
”。
上一节:
Bootstrap5_按钮组
下一节:
Bootstrap5_进度条