必须重写@keyframes progress-bar-stripes并同步更新.progress-bar-animated的完整animation声明,三者名称、数值、单位须严格一致;scss用户应优先修改$progress-bar-animation-timing变量。

直接改 animation-duration 无效,因为 Bootstrap 5 的进度条动画由 @keyframes progress-bar-stripes 驱动,且其时长被硬编码在 .progress-bar-animated 的 animation 声明里——你不能只调一个属性就覆盖整个复合动画声明。
必须重写 @keyframes progress-bar-stripes 并同步更新 .progress-bar-animated
纯 CSS 覆盖(适用于 CDN 或已编译 CSS)不是“改 duration”,而是整套替换。三者必须完全一致:
-
@keyframes progress-bar-stripes名字必须一字不差,且定义要放在你自己的 CSS 文件末尾(或<style></style>标签中),确保加载顺序在 Bootstrap 之后 -
.progress-bar-animated的完整animation声明必须显式重写,例如:animation: progress-bar-stripes 0.4s linear infinite—— 不能只写animation-duration -
background-size和@keyframes中的background-position位移值单位、数值要匹配(比如都用0.5rem,而非一个用px一个用rem)
SCSS 用户优先改变量 $progress-bar-animation-timing
如果你用的是 Sass 构建流程(如 Vue CLI、Create React App 配了 Sass),这是最干净的方式:
- 在导入 Bootstrap 前,先重定义变量:
$progress-bar-animation-timing: 0.4s linear infinite; - 再执行
@import "bootstrap/scss/bootstrap"; - 无需写任何
@keyframes或选择器,所有.progress-bar-animated自动生效 - 注意:Bootstrap 5.3+ 仍支持该变量;4.x 版本对应的是
$progress-bar-striped-animation-timing
为什么加了 .progress-bar-animated 还没动画?
常见失效原因不是速度问题,而是基础条件没满足:
- 父容器必须有
.progress类,且其overflow: hidden未被覆盖(否则条纹会溢出) -
.progress-bar必须同时具备.progress-bar-animated和.progress-bar-striped(Bootstrap 5 中后者提供条纹背景,前者触发动画) - 浏览器不支持该动画(Safari 15.4 以下、所有 IE 完全失效,且无降级提示)
- 服务端返回了超限 width(如
102%),会导致背景位移错乱,务必用Math.min(100, Math.max(0, value))截断
真正卡点在于:动画不是独立存在的,它依赖 background-size、background-position、@keyframes、animation 四者数值严格对齐。哪怕 background-size: 1rem 而 @keyframes 里写 to { background-position: 1px },也会视觉撕裂或回弹。
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!











