Skip to main content Skip to docs navigation

图片

选择图片进行响应式行为(因此它们永远不会比其父级更宽)并向其添加轻量级样式的文档和示例 - 全部通过类。

响应式图片

¥Responsive images

Bootstrap 中的图片采用 .img-fluid 进行响应。这会将 max-width: 100%;height: auto; 应用于图片,以便它随父宽度缩放。

¥Images in Bootstrap are made responsive with .img-fluid. This applies max-width: 100%; and height: auto; to the image so that it scales with the parent width.

PlaceholderResponsive image
html
<img src="..." class="img-fluid" alt="...">

图片缩略图

¥Image thumbnails

除了我们的 border-radius 实用程序 之外,你还可以使用 .img-thumbnail 为图片提供圆角 1px 边框外观。

¥In addition to our border-radius utilities, you can use .img-thumbnail to give an image a rounded 1px border appearance.

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

对齐图片

¥Aligning images

使用 辅助浮动类文本对齐类 对齐图片。block 级图片可以使用 .mx-auto 边距实用程序类居中。

¥Align images with the helper float classes or text alignment classes. block-level images can be centered using the .mx-auto margin utility class.

Placeholder200x200 Placeholder200x200
html
<img src="..." class="rounded float-start" alt="...">
<img src="..." class="rounded float-end" alt="...">
Placeholder200x200
html
<img src="..." class="rounded mx-auto d-block" alt="...">
Placeholder200x200
html
<div class="text-center">
  <img src="..." class="rounded" alt="...">
</div>

图片

¥Picture

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

¥If you are using the <picture> element to specify multiple <source> elements for a specific <img>, make sure to add the .img-* classes to the <img> and not to the <picture> tag.

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

CSS

Sass 变量

¥Sass variables

变量可用于图片缩略图。

¥Variables are available for image thumbnails.

$thumbnail-padding:                 .25rem;
$thumbnail-bg:                      var(--#{$prefix}body-bg);
$thumbnail-border-width:            var(--#{$prefix}border-width);
$thumbnail-border-color:            var(--#{$prefix}border-color);
$thumbnail-border-radius:           var(--#{$prefix}border-radius);
$thumbnail-box-shadow:              var(--#{$prefix}box-shadow-sm);