logo图片
Bootstrap教程

Bootstrap 徽章和标签

Bootstrap 徽章和标签


Bootstrap徽章

Bootstrap徽章是用于指示与特定链接关联多少项目的数字指示器。徽章用于突出显示新的或未读的项目。
元素中的 class .badge 用于创建徽章。

Bootstrap徽章示例

 <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
 
</head>
<body>
<div class="container">
  <h2>Badges</h2>
  <a href="#">News <span class="badge">5</span></a><br>
  <a href="#">Comments <span class="badge">10</span></a><br>
  <a href="#">Updates <span class="badge">2</span></a>
</div>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>

Bootstrap徽章示例2

您还可以在其他元素(例如按钮)中使用徽章。
让我们举个例子看看如何将徽章添加到按钮。
 <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  
</head>
<body>
<div class="container">
  <h2>Badges on Buttons</h2>
  <button type="button" class="btn btn-primary">Primary <span class="badge">7</span></button>
  <button type="button" class="btn btn-success">Success <span class="badge">3</span></button>    
  <button type="button" class="btn btn-danger">Danger <span class="badge">5</span></button>        
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>

Bootstrap标签

Bootstrap标签用于指定有关商品的额外信息,例如页面的数量,技巧或其他组成。
class .label 用于显示标签。

Bootstrap 标签示例

 <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Label Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body> 
 
<div class="container">
  <h2>Labels Example</h2>
  <h1>Update <span class="label label-default">New</span></h1>
  <h2>Update<span class="label label-default">New</span></h2>
  <h3>Update <span class="label label-default">New</span></h3>
  <h4>Update<span class="label label-default">New</span></h4>
  <h5>Update<span class="label label-default">New</span></h5>
  <h6>Update<span class="label label-default">New</span></h6>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>

Bootstrap 标签示例2: 更改颜色

我们可以使用上下文标签类来更改标签颜色。
 <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Contextual Label</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  
</head>
<body> 
 
<div class="container">
  <h2>Contextual Label Classes</h2> 
  <span class="label label-default">default Label</span>
  <span class="label label-primary">Primary Label</span>
  <span class="label label-success">Success Label</span>
  <span class="label label-info">Info Label</span>
  <span class="label label-warning">Warning Label</span>
  <span class="label label-danger">Danger Label</span>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>

Bootstrap 标签示例3

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Case</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
 
</head>
<body> 
 
<div class="container">
  <h2>Labels Example</h2>
  <h3>Update <span class="label label-default">new</span>
  <h3>Update <span class="label label-primary">new</span>
  <h3>Update <span class="label label-success">new</span>
  <h3>Update <span class="label label-info">new</span>
  <h3>Update <span class="label label-warning">new</span>
  <h3>Update <span class="label label-danger">new</span>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>

Bootstrap 4徽章

在Bootstrap 4中,徽章也可以与标题标签(

......

)一起使用。在元素中将.badge类与上下文类(例如.badge-secondary)一起使用,以创建矩形标记。

示例:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Badges Example</h2>
  <h1>h1 heading <span class="badge badge-secondary">New</span></h1>
  <h2>h2 heading <span class="badge badge-secondary">New</span></h2>
  <h3>h3 heading <span class="badge badge-secondary">New</span></h3>
  <h4>h4 heading <span class="badge badge-secondary">New</span></h4>
  <h5>h5 heading <span class="badge badge-secondary">New</span></h5>
  <h6>h6 heading <span class="badge badge-secondary">New</span></h6>
</div>
</body>
</html>

上下文徽章

您可以使用上下文类来更改徽章的颜色。

示例:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Contextual Badges Example</h2>
  <span class="badge badge-primary">Primary Badge</span>
  <span class="badge badge-secondary">Secondary Badge</span>
  <span class="badge badge-success">Success Badge</span>
  <span class="badge badge-danger">Danger Badge</span>
  <span class="badge badge-warning">Warning Badge</span>
  <span class="badge badge-info">Info Badge</span>
  <span class="badge badge-light">Light Badge</span>
  <span class="badge badge-dark">Dark Badge</span>
</div>
</body>
</html>

Bootstrap 4 Pill Badges

Pill Badges用于使徽章更圆。使用class.badge-pill类添加Pill Badges。

示例:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h2>Pill Badges Example</h2>
  <span class="badge badge-pill badge-primary">Primary</span>
  <span class="badge badge-pill badge-secondary">Secondary</span>
  <span class="badge badge-pill badge-success">Success</span>
  <span class="badge badge-pill badge-danger">Danger</span>
  <span class="badge badge-pill badge-warning">Warning</span>
  <span class="badge badge-pill badge-info">Info</span>
  <span class="badge badge-pill badge-light">Light</span>
  <span class="badge badge-pill badge-dark">Dark</span>
</div>
</body>
</html>
昵称: 邮箱:
Copyright © 2020 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4