颜色和背景
设置与前景色形成对比的背景色。
概述
🌐 Overview
颜色和背景辅助工具将我们的.text-*工具和.bg-*工具的功能结合在一个类中。使用我们的Sass color-contrast() 函数,我们可以自动为特定的 background-color 确定对比的 color。
🌐 Color and background helpers combine the power of our .text-* utilities and .bg-* utilities in one class. Using our Sass color-contrast() function, we automatically determine a contrasting color for a particular background-color.
注意! 目前不支持 CSS 原生的 color-contrast 函数,所以我们通过 Sass 使用我们自己的实现。这意味着通过 CSS 变量自定义我们的主题颜色可能会导致这些工具的颜色对比问题。
<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> Accessibility tip: Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies like screen readers. Please ensure the meaning is obvious from the content itself (e.g., the visible text with a sufficient color contrast) or is included through alternative means, such as additional text hidden with the .visually-hidden class.
带组件
🌐 With components
在组合的 .text-* 和 .bg-* 类的位置使用它们,例如在 徽章 上:
🌐 Use them in place of combined .text-* and .bg-* classes, like on badges:
<span class="badge text-bg-primary">Primary</span>
<span class="badge text-bg-info">Info</span> 或者在卡片上:
🌐 Or on cards:
Some quick example text to build on the card title and make up the bulk of the card’s content.
Some quick example text to build on the card title and make up the bulk of the card’s content.
<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>