Images

Documentation and examples for opting images into responsive behavior (so they never become wider than their parent) and add lightweight styles to them—all via classes.

Responsive images

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.

Images - 图1

html

  1. <img src="..." class="img-fluid" alt="...">

Image thumbnails

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

Images - 图2

html

  1. <img src="..." class="img-thumbnail" alt="...">

Aligning images

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

Images - 图3

html

  1. <img src="..." class="rounded float-start" alt="...">
  2. <img src="..." class="rounded float-end" alt="...">

Images - 图4

html

  1. <img src="..." class="rounded mx-auto d-block" alt="...">

Images - 图5

html

  1. <div class="text-center">
  2. <img src="..." class="rounded" alt="...">
  3. </div>

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.

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

CSS

Sass variables

Variables are available for image thumbnails.

scss/_variables.scss

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