Added in v5.2
View on GitHub
顏色與背景(Color and background)
設定背景色並自動搭配對比前景色。
本頁內容
概覽(Overview)
顏色與背景輔助類別將 .text-* 通用類別和 .bg-* 通用類別的功能整合在一個類別中。透過使用我們的 Sass color-contrast() 函式,我們會自動為特定的 background-color 決定對比的 color。
請注意! 目前 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
<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> 無障礙提示: 僅使用顏色來傳達意義只提供了視覺指示,這不會傳達給使用輔助技術(如螢幕閱讀器)的使用者。請確保意義從內容本身就很明顯(例如,具有_足夠_色彩對比度的可見文字),或透過替代方式包含,例如使用 .visually-hidden 類別隱藏的額外文字。
與元件搭配使用(With components)
使用它們來取代組合的 .text-* 和 .bg-* 類別,例如在標記上:
Primary
Info
<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.
<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>