Source

图片

将图像选择为响应式行为的文档和示例(因此它们永远不会大于其父元素)并向它们添加轻量级样式 - 全部通过类。

响应式图像

Bootstrap 中的图像使用.img-fluid. max-width: 100%;height: auto;应用于图像,使其与父元素一起缩放。

Placeholder Responsive image
<img src="..." class="img-fluid" alt="Responsive image">
SVG 图像和 IE 10

在 Internet Explorer 10 中,SVG 图像.img-fluid的大小不成比例。要解决此问题,请width: 100% \9;在必要时添加。此修复不正确地调整其他图像格式的大小,因此 Bootstrap 不会自动应用它。

图像缩略图

除了我们的边界半径实用程序之外,您还可以使用.img-thumbnail为图像提供 1 像素的圆形边框外观。

A generic square placeholder image with a white border around it, making it resemble a photograph taken with an old instant camera 200x200
<img src="..." alt="..." class="img-thumbnail">

对齐图像

将图像与辅助浮点类文本对齐类对齐block级图像可以使用margin.mx-auto实用程序类居中。

Placeholder 200x200 Placeholder 200x200
<img src="..." class="rounded float-left" alt="...">
<img src="..." class="rounded float-right" alt="...">
Placeholder 200x200
<img src="..." class="rounded mx-auto d-block" alt="...">
Placeholder 200x200
<div class="text-center">
  <img src="..." class="rounded" alt="...">
</div>

图片

如果您使用元素为特定<picture>的 指定多个元素,请确保将类添加到标签而不是标签。<source><img>.img-*<img><picture>

<picture>
  <source srcset="..." type="image/svg+xml">
  <img src="..." class="img-fluid img-thumbnail" alt="...">
</picture>