跳到主要內容 跳到文檔導航
in English

圖片

將圖像選擇為響應式行為(因此它們永遠不會變得大於其父元素)並向它們添加輕量級樣式的文檔和示例 - 全部通過類。

響應式圖像

Bootstrap 中的圖像使用.img-fluid. 這適用於圖像max-width: 100%;height: auto;以便它與父元素一起縮放。

Placeholder Responsive image
<img src="..." class="img-fluid" alt="...">

圖像縮略圖

除了我們的邊界半徑實用程序之外,您還可以使用.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="..." class="img-thumbnail" alt="...">

對齊圖像

將圖像與輔助浮點類文本對齊類對齊block級圖像可以使用margin.mx-auto實用程序類居中。

Placeholder 200x200 Placeholder 200x200
<img src="..." class="rounded float-start" alt="...">
<img src="..." class="rounded float-end" 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>

薩斯

變量

變量可用於圖像縮略圖。

$thumbnail-padding:                 .25rem;
$thumbnail-bg:                      $body-bg;
$thumbnail-border-width:            $border-width;
$thumbnail-border-color:            $gray-300;
$thumbnail-border-radius:           $border-radius;
$thumbnail-box-shadow:              $box-shadow-sm;