Bootstrap badge(徽章) 与 label(标记) 样式

badge

badge(徽章)是与链接关联的项目数量的数字指示器:

News 5

Comments 10

Updates 2

数字 (5, 10, 与 2) 都是 badge(徽章)。

使用 .badge 样式与 <span> 元素来创建徽章:

实例
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>badge 样式</h2>
  12. <a href="#">News <span class="badge">5</span></a><br>
  13. <a href="#">Comments <span class="badge">10</span></a><br>
  14. <a href="#">Updates <span class="badge">2</span></a>
  15. </div>
  16. </body>
  17. </html>

徽章也可以用于其他元素,如按钮:

下面的实例演示如何向按钮添加徽章:

实例
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>按钮上的徽章</h2>
  12. <button type="button" class="btn btn-primary">Primary <span class="badge">7</span></button>
  13. <button type="button" class="btn btn-success">Success <span class="badge">3</span></button>
  14. <button type="button" class="btn btn-danger">Danger <span class="badge">5</span></button>
  15. </div>
  16. </body>
  17. </html>

Label(标签)

标签用于提供有关某事物的附加信息:

Example New

Example New

Example New

Example New
Example New

使用 .label 类,然后是带有 6 个上下文样式类(.label-default, .label-primary, .label-success, .label-info, .label-warning or .label-danger)中的 1 个的 <span> 元素来创建一个标签:

实例
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>Labels</h2>
  12. <h1>Example <span class="label label-default">New</span></h1>
  13. <h2>Example <span class="label label-default">New</span></h2>
  14. <h3>Example <span class="label label-default">New</span></h3>
  15. <h4>Example <span class="label label-default">New</span></h4>
  16. <h5>Example <span class="label label-default">New</span></h5>
  17. <h6>Example <span class="label label-default">New</span></h6>
  18. </div>
  19. </body>
  20. </html>

以下实例显示了所有上下文标签类:

Default Label Primary Label Success Label Info Label Warning Label Danger Label
实例
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap 实例</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="https://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <h2>上下文标签样式类</h2>
  12. <p>上下文样式类可用于为标签添加颜色</p>
  13. <span class="label label-default">Default Label</span>
  14. <span class="label label-primary">Primary Label</span>
  15. <span class="label label-success">Success Label</span>
  16. <span class="label label-info">Info Label</span>
  17. <span class="label label-warning">Warning Label</span>
  18. <span class="label label-danger">Danger Label</span>
  19. </div>
  20. </body>
  21. </html>