メインコンテンツへスキップ ドキュメントナビゲーションへスキップ

レスポンシブな動作(親要素よりも幅広にならないように)をする画像を選択し、軽量なスタイルを追加するためのドキュメントと例 - すべてクラスを介して行います。

このページの内容

レスポンシブ画像

Bootstrapの画像は、.img-fluidでレスポンシブになります。これは、画像にmax-width: 100%;height: auto;を適用し、親要素の幅に合わせて拡大縮小できるようにします。

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

画像サムネイル

border-radiusユーティリティに加えて、.img-thumbnailを使用して、画像に丸みを帯びた1pxの境界線を追加できます。

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

画像の配置

ヘルパーフロートクラスまたはテキスト配置クラスを使用して画像を配置します。 blockレベルの画像は、.mx-autoマージンユーティリティクラスを使用して中央に配置できます。

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

ピクチャ

特定の<img>に複数の<source>要素を指定するために<picture>要素を使用する場合は、.img-*クラスを<picture>タグではなく<img>に追加してください。

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

CSS

Sass変数

変数は画像サムネイルに使用できます。

$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);