旋转图标(Spinners)
使用完全由HTML,CSS而不使用JavaScript构建的Bootstrap旋转器指示组件或页面的加载状态。.
关于
Bootstrap “旋转器”可用于显示项目中的加载状态。它们只使用HTML和CSS构建,这意味着您不需要任何JavaScript来创建它们。但是,您需要一些自定义JavaScript来切换它们的可见性。它们的外观、对齐方式和大小都可以通过我们惊人的实用程序类轻松定制。
为了便于访问,这里的每个加载程序都包含 role="status"
和嵌套的 <span class="visually-hidden">Loading...</span>
。
prefers-reduced-motion
媒体查询。请参阅我们的可访问性文档的简化运动部分。
边框旋转器
使用边框旋转器作为轻量级加载指示器。
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
颜色
边框旋转器使用 currentColor
作为 border-color
,这意味着您可以使用文本颜色实用程序自定义颜色。您可以在标准旋转器上使用我们的任何文本颜色实用程序。
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-secondary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-success" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-danger" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-warning" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-info" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-light" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-dark" role="status">
<span class="visually-hidden">Loading...</span>
</div>
border-color
工具? 每个边框旋转器至少为一侧指定一个 transparent
边框,因此.border-{color}
实用程序将覆盖该边框。
不断增长的旋转器
如果您不喜欢边框旋转器,请切换到“生长”旋转器。虽然从技术上讲它不会旋转,但它确实会反复生长!
<div class="spinner-grow" role="status">
<span class="visually-hidden">Loading...</span>
</div>
同样,这个旋转器是用 currentColor
构建的,因此您可以使用文本颜色工具轻松地更改它的外观。这里是蓝色,以及支持的变体。
<div class="spinner-grow text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow text-secondary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow text-success" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow text-danger" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow text-warning" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow text-info" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow text-light" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow text-dark" role="status">
<span class="visually-hidden">Loading...</span>
</div>
对齐
Bootstrap中的旋转器是用 rem
, currentColor
和 display: inline-flex
构建的。这意味着它们可以很容易地调整大小、重新着色和快速对齐。
页边空白
使用诸如.m-5
之类的 边距实用程序以方便间距。
<div class="spinner-border m-5" role="status">
<span class="visually-hidden">Loading...</span>
</div>
放置方式
使用 flexbox 实用程序, float 实用程序 或 文本对齐 实用程序,可以在任何情况下将旋转器精确放置在需要它们的位置。
Flex
<div class="d-flex justify-content-center">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div class="d-flex align-items-center">
<strong>Loading...</strong>
<div class="spinner-border ms-auto" role="status" aria-hidden="true"></div>
</div>
浮动
<div class="clearfix">
<div class="spinner-border float-end" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
文字对齐
<div class="text-center">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
尺寸
添加 .spinner-border-sm
和 .spinner-grow-sm
生成一个较小的旋转器,可以在其他组件中快速使用。
<div class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow spinner-grow-sm" role="status">
<span class="visually-hidden">Loading...</span>
</div>
或者,根据需要使用自定义CSS或内联样式来更改尺寸。
<div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status">
<span class="visually-hidden">Loading...</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">Loading...</span>
</button>
<button class="btn btn-primary" type="button" disabled>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
Loading...
</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">Loading...</span>
</button>
<button class="btn btn-primary" type="button" disabled>
<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
Loading...
</button>