跳到主要内容

背景工具

背景工具类包含背景色、渐变和背景色透明度控制,适用于各种 UI 场景。

背景色

所有主题色和系统色均可作为背景色使用:

bg-primary
bg-secondary
bg-success
bg-danger
bg-warning
bg-info
bg-light
bg-dark
<div class="bg-primary text-white p-3">主要背景</div>
<div class="bg-success text-white p-3">成功背景</div>
<div class="bg-danger text-white p-3">危险背景</div>
<div class="bg-warning p-3">警告背景</div>

背景渐变

添加 .bg-gradient 为背景色叠加一个线性渐变效果:

<div class="bg-primary bg-gradient text-white p-4 rounded">渐变背景</div>
<div class="bg-success bg-gradient text-white p-4 rounded">成功渐变</div>
<div class="bg-dark bg-gradient text-white p-4 rounded">深色渐变</div>

背景色透明度

Bootstrap 5.3 新增了背景色透明度工具类:

类名透明度
.bg-opacity-1010%
.bg-opacity-2525%
.bg-opacity-5050%
.bg-opacity-7575%
.bg-opacity-100100%
<div class="bg-primary bg-opacity-10 p-3 rounded">10% 透明度</div>
<div class="bg-primary bg-opacity-25 p-3 rounded">25% 透明度</div>
<div class="bg-primary bg-opacity-50 p-3 rounded">50% 透明度</div>
<div class="bg-primary bg-opacity-75 p-3 rounded">75% 透明度</div>

其他背景类

类名用途
.bg-transparent透明背景
.bg-body页面默认背景色
.bg-body-tertiary三级背景色(深色模式下自动适配)
.bg-body-secondary二级背景色

本网站使用 Cookie 来提升您的浏览体验。隐私政策