加载状态
Bootstrap的“spinners”可用于显示项目中的加载状态。它们只使用HTML和CSS构建,这意味着您不需要任何JavaScript来创建它们。但是,您需要一些自定义JavaScript来切换它们的可见性。它们的外观、对齐和大小可以通过我们令人惊叹的实用程序类轻松定制。
为了便于访问,这里的每个加载程序都包括 role=“status"
和嵌套的 <span class="visually-hidden">加载中...</span>
。
加载中...
<div class="spinner-border" role="status"> <span class="visually-hidden">加载中...</span> </div>
颜色
你可以使用 .text-primary
等这样的文本颜色来定义加载动画的颜色。
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
<div class="spinner-border text-primary" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-border text-secondary" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-border text-success" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-border text-danger" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-border text-warning" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-border text-info" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-border text-light" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-border text-dark" role="status"> <span class="visually-hidden">加载中...</span> </div>
为什么不使用
border-color
工具?每个旋转动画至少为一侧指定一个透明边框,因此 .border-{color}
工具将覆盖该边框。渐变增长式的加载
加载中...
<div class="spinner-grow" role="status"> <span class="visually-hidden">加载中...</span> </div>
颜色
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
加载中...
<div class="spinner-grow text-primary" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow text-secondary" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow text-success" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow text-danger" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow text-warning" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow text-info" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow text-light" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow text-dark" role="status"> <span class="visually-hidden">加载中...</span> </div>
对齐
外边距
使用类似于 .m-5
这样的 margin
工具。
加载中...
<div class="spinner-border m-5" role="status"> <span class="visually-hidden">加载中...</span> </div>
布局
Flex
加载中...
<div class="d-flex justify-content-center"> <div class="spinner-border" role="status"> <span class="visually-hidden">加载中...</span> </div> </div>
加载中...
<div class="d-flex align-items-center"> <strong>加载中...</strong> <div class="spinner-border ms-auto" role="status" aria-hidden="true"></div> </div>
Floats
加载中...
<div class="clearfix"> <div class="spinner-border float-end" role="status"> <span class="visually-hidden">加载中...</span> </div> </div>
Text align
加载中...
<div class="text-center"> <div class="spinner-border" role="status"> <span class="visually-hidden">加载中...</span> </div> </div>
大小
加载中...
加载中...
<div class="spinner-border spinner-border-sm" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow spinner-grow-sm" role="status"> <span class="visually-hidden">加载中...</span> </div>
或者,使用自定义CSS或内联样式根据需要更改维度。
加载中...
加载中...
<div class="spinner-border" style="width: 3rem; height: 3rem;" role="status"> <span class="visually-hidden">加载中...</span> </div> <div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status"> <span class="visually-hidden">加载中...</span> </div>
按钮
<button class="btn btn-primary" type="button" disabled> <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> <span class="visually-hidden">加载中...</span> </button> <button class="btn btn-primary" type="button" disabled> <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> 加载中... </button>
<button class="btn btn-primary" type="button" disabled> <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span> <span class="visually-hidden">加载中...</span> </button> <button class="btn btn-primary" type="button" disabled> <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span> 加载中... </button>