Skip to main content Skip to docs navigation

画像 Images

画像をレスポンシブ動作にオプトインし(親より広くならないように)、クラスを介して軽量なスタイルを追加するためのドキュメントと例です。

レスポンシブ画像

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

PlaceholderResponsive 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 camera200x200
html
<img src="..." class="img-thumbnail" alt="...">

画像の配置

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

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-*クラスを<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);