5.颜色

文本颜色

Bootstrap 5 有一些上下文类,可用于提供“由颜色表达的某种意义”。

针对文本颜色的类是:

  • .text-muted
  • .text-primary
  • .text-success
  • .text-info
  • .text-warning
  • .text-danger
  • .text-secondary
  • .text-white
  • .text-dark
  • .text-body(默认的 body 颜色/通常为黑色)
  • .text-light

实例

 
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h1>上下文颜色</h1>
  <p>请使用上下文类来提供“由颜色表达的某种意义”。</p>
  <p class="text-muted">此文本已静音。</p>
  <p class="text-primary">此文字很重要。</p>
  <p class="text-success">此文本表示成功。</p>
  <p class="text-info">此文字代表了一些信息。</p>
  <p class="text-warning">此文本表示警告。</p>
  <p class="text-danger">此文字代表危险。</p>
  <p class="text-secondary">次要文本。</p>
  <p class="text-dark">此文字为深灰色。</p>
  <p class="text-body">默认主体颜色(通常为黑色)。</p>
  <p class="text-light">此文本为浅灰色(在白色背景上)。</p>
  <p class="text-white">这段文字是白色的(在白色背景上)。</p>
</div>

</body>
</html>

您还可以使用 .text-black-50 或 .text-white-50 类为黑色或白色文本添加 50% 的不透明度:

实例

 
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h1>不透明度文本颜色</h1>
  <p>请使用 .text-black-50 或 .text-white-50 类为黑色或白色文本添加 50% 的不透明度:</p>
  <p class="text-black-50">白色背景上不透明度为 50% 的黑色文本</p>
  <p class="text-white-50 bg-dark">黑色背景上不透明度为 50% 的白色文本</p>
</div>

</body>
</html>

背景颜色

针对背景颜色的类是:

  • .bg-primary
  • .bg-success
  • .bg-info
  • .bg-warning
  • .bg-danger
  • .bg-secondary
  • .bg-dark
  • .bg-light

请注意,背景颜色不会设置文本颜色,因此在某些情况下,您需要将它们与 .text-* 颜色类一起使用。

实例

 
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h1>上下文背景</h1>
  <p>请使用上下文背景类来提供“由颜色表达的某种意义”。</p>
  <p>请注意,如果您想要不同的文本颜色,您还可以添加 .text-* 类:</p>
  <p class="bg-primary text-white">此文本很重要。</p>
  <p class="bg-success text-white">此文本表示成功。</p>
  <p class="bg-info text-white">此文本代表了一些信息。</p>
  <p class="bg-warning text-white">此文本表示警告。</p>
  <p class="bg-danger text-white">此文本代表危险。</p>
  <p class="bg-secondary text-white">次要背景颜色。</p>
  <p class="bg-dark text-white">深灰色背景颜色。</p>
  <p class="bg-light text-dark">浅灰色背景色。</p>
</div>

</body>
</html>

 

posted @ 2022-04-03 20:01  随遇而安==  阅读(79)  评论(0编辑  收藏  举报