跳到主要内容 跳到文档导航

颜色和背景

设置与前景色形成对比的背景色。

在此页

概述

颜色和背景类将我们的.text-*实用程序.bg-*实用程序的功能结合在一个类中。使用我们的 Sass color-contrast()函数,我们自动确定特定background-colorcolor.

小心!目前不支持 CSS 原生color-contrast函数,因此我们通过 Sass 使用我们自己的函数。这意味着通过 CSS 变量自定义我们的主题颜色可能会导致这些实用程序出现颜色对比问题。
Primary with contrasting color
Secondary with contrasting color
Success with contrasting color
Danger with contrasting color
Warning with contrasting color
Info with contrasting color
Light with contrasting color
Dark with contrasting color
HTML
<div class="text-bg-primary p-3">Primary with contrasting color</div>
<div class="text-bg-secondary p-3">Secondary with contrasting color</div>
<div class="text-bg-success p-3">Success with contrasting color</div>
<div class="text-bg-danger p-3">Danger with contrasting color</div>
<div class="text-bg-warning p-3">Warning with contrasting color</div>
<div class="text-bg-info p-3">Info with contrasting color</div>
<div class="text-bg-light p-3">Light with contrasting color</div>
<div class="text-bg-dark p-3">Dark with contrasting color</div>

在组件上使用

使用它们代替组合.text-*.bg-*类,例如徽章

Primary Info
HTML
<span class="badge text-bg-primary">Primary</span>
<span class="badge text-bg-info">Info</span>

或者在卡片上:

Header

Some quick example text to build on the card title and make up the bulk of the card's content.

Header

Some quick example text to build on the card title and make up the bulk of the card's content.

HTML
<div class="card text-bg-primary mb-3" style="max-width: 18rem;">
  <div class="card-header">Header</div>
  <div class="card-body">
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
  </div>
</div>
<div class="card text-bg-info mb-3" style="max-width: 18rem;">
  <div class="card-header">Header</div>
  <div class="card-body">
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
  </div>
</div>