Bootstrap5 コンテナ
前の章で、Bootstrap はウェブサイトのコンテンツを包むためのコンテナ要素が必要であることを学びました。
次の2つのコンテナクラスを使用できます:
- .containerクラスはデフォルトのコンテナで、固定幅のレイアウトを提供し、幅は画面サイズに応じて調整されます。
- .container-fluidクラスは 100% 幅で、ビューポート全体を占めるコンテナに使用されます。このコンテナクラスを使用すると、常に画面全体の幅いっぱいになり、全画面レイアウトに適しています。

固定幅
.containerクラスは固定幅のレスポンシブページを作成するために使用されます。
注意:幅(max-width)は、画面の幅に応じて同じ比率で拡大または縮小されます。
| 極小画面 <576px |
小画面 ≥576px |
中画面 ≥768px |
大画面 ≥992px |
特大画面 ≥1200px |
超特大画面 ≥1400px |
|
|---|---|---|---|---|---|---|
| max-width | 100% | 540px | 720px | 960px | 1140px | 1320px |
以下の例では、ブラウザウィンドウのサイズを調整して、コンテナの幅が異なる画面でどう変化するかを確認できます:
Bootstrap5 .container の例
<div class="container">
<h1>私の最初のBootstrapページ</h1>
<p>これはテキストです。</p>
</div>
試してみる »
注意:超特大画面(≥1400px)は Bootstrap 5 で新しく追加されました。Bootstrap 4 での最大は特大画面(≥1200px)でした。
100% 幅
.container-fluidクラスは全画面サイズのコンテナを作成するために使用され、コンテナは常に画面全体の幅にわたります(width は常に 100%):
Bootstrap5 .container-fluid の例
<div class="container-fluid">
<h1>私の最初のBootstrapページ</h1>
<p>.container-fluid を使用すると、100% 幅で、ビューポート全体を占めるコンテナになります。</p>
</div>
試してみる »
コンテナのパディング
デフォルトでは、コンテナには左右のパディングがあり、上下にはパディングがありません。Bootstrap は余白を埋めるためのスペーシングクラスをいくつか提供しています。たとえば、.pt-5は上部のパディングを埋めるために使用されます:
コンテナの枠線と色
Bootstrap は、コンテナのスタイルを設定するための枠線(border)と色(bg-dark、bg-primary など)のクラスも提供しています:
Bootstrap5 の例
<div class="container p-5 my-5 border"></div>
<div class="container p-5 my-5 bg-dark text-white"></div>
<div class="container p-5 my-5 bg-primary text-white"></div>
試してみる »
後の章でこれらのスタイルについて詳しく説明します。
レスポンシブコンテナ
あなたは使用できます.container-sm|md|lg|xlクラスを使用してレスポンシブコンテナを作成できます。
コンテナの max-width 属性値は、画面のサイズに応じて変化します。
| Class | 極小画面 <576px |
小画面 ≥576px |
中画面 ≥768px |
大画面 ≥992px |
特大画面 ≥1200px |
超特大画面 ≥1400px |
|---|---|---|---|---|---|---|
.container-sm |
100% | 540px | 720px | 960px | 1140px | 1320px |
.container-md |
100% | 100% | 720px | 960px | 1140px | 1320px |
.container-lg |
100% | 100% | 100% | 960px | 1140px | 1320px |
.container-xl |
100% | 100% | 100% | 100% | 1140px | 1320px |
.container-xxl |
100% | 100% | 100% | 100% | 100% | 1320px |
Bootstrap5 の例
<div class="container-sm">.container-sm</div>
<div class="container-md">.container-md</div>
<div class="container-lg">.container-lg</div>
<div class="container-xl">.container-xl</div>
<div class="container-xxl">.container-xxl</div>
試してみる »