图片
选择图片进行响应式行为(因此它们永远不会比其父级更宽)并向其添加轻量级样式的文档和示例 - 全部通过类。
响应式图片
¥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.
<img src="..." class="img-fluid" alt="..."> 图片缩略图
¥Image thumbnails
除了我们的 边框半径工具,你还可以使用 .img-thumbnail 为图片添加 1px 圆角边框。
¥In addition to our border-radius utilities, you can use .img-thumbnail to give an image a rounded 1px border appearance.
<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.
<img src="..." class="rounded float-start" alt="...">
<img src="..." class="rounded float-end" alt="..."> <img src="..." class="rounded mx-auto d-block" alt="..."> <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);