col-
bootstrap5.css
bootstrap5.css
.col-auto {
flex: 0 0 auto;
width: auto;
}
bootstrap5.css
.col-1 {
flex: 0 0 auto;
width: 8.3333333333%;
}
bootstrap5.css
.col-2 {
flex: 0 0 auto;
width: 16.6666666667%;
}
bootstrap5.css
.col-3 {
flex: 0 0 auto;
width: 25%;
}
bootstrap5.css
.col-4 {
flex: 0 0 auto;
width: 33.3333333333%;
}
bootstrap5.css
.col-5 {
flex: 0 0 auto;
width: 41.6666666667%;
}
bootstrap5.css
.col-6 {
flex: 0 0 auto;
width: 50%;
}
bootstrap5.css
.col-7 {
flex: 0 0 auto;
width: 58.3333333333%;
}
bootstrap5.css
.col-8 {
flex: 0 0 auto;
width: 66.6666666667%;
}
bootstrap5.css
.col-9 {
flex: 0 0 auto;
width: 75%;
}
bootstrap5.css
.col-10 {
flex: 0 0 auto;
width: 83.3333333333%;
}
bootstrap5.css
.col-11 {
flex: 0 0 auto;
width: 91.6666666667%;
}
bootstrap5.css
.col-12 {
flex: 0 0 auto;
width: 100%;
}
bootstrap5.css
@media (min-width: 576px) {
.col-sm {
flex: 1 0 0%;
}
.row-cols-sm-auto > * {
flex: 0 0 auto;
width: auto;
}
.row-cols-sm-1 > * {
flex: 0 0 auto;
width: 100%;
}
.row-cols-sm-2 > * {
flex: 0 0 auto;
width: 50%;
}
.row-cols-sm-3 > * {
flex: 0 0 auto;
width: 33.3333333333%;
}
.row-cols-sm-4 > * {
flex: 0 0 auto;
width: 25%;
}
.row-cols-sm-5 > * {
flex: 0 0 auto;
width: 20%;
}
.row-cols-sm-6 > * {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-sm-auto {
flex: 0 0 auto;
width: auto;
}
.col-sm-1 {
flex: 0 0 auto;
width: 8.3333333333%;
}
.col-sm-2 {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-sm-3 {
flex: 0 0 auto;
width: 25%;
}
.col-sm-4 {
flex: 0 0 auto;
width: 33.3333333333%;
}
.col-sm-5 {
flex: 0 0 auto;
width: 41.6666666667%;
}
.col-sm-6 {
flex: 0 0 auto;
width: 50%;
}
.col-sm-7 {
flex: 0 0 auto;
width: 58.3333333333%;
}
.col-sm-8 {
flex: 0 0 auto;
width: 66.6666666667%;
}
.col-sm-9 {
flex: 0 0 auto;
width: 75%;
}
.col-sm-10 {
flex: 0 0 auto;
width: 83.3333333333%;
}
.col-sm-11 {
flex: 0 0 auto;
width: 91.6666666667%;
}
.col-sm-12 {
flex: 0 0 auto;
width: 100%;
}
.offset-sm-0 {
margin-left: 0;
}
.offset-sm-1 {
margin-left: 8.3333333333%;
}
.offset-sm-2 {
margin-left: 16.6666666667%;
}
.offset-sm-3 {
margin-left: 25%;
}
.offset-sm-4 {
margin-left: 33.3333333333%;
}
.offset-sm-5 {
margin-left: 41.6666666667%;
}
.offset-sm-6 {
margin-left: 50%;
}
.offset-sm-7 {
margin-left: 58.3333333333%;
}
.offset-sm-8 {
margin-left: 66.6666666667%;
}
.offset-sm-9 {
margin-left: 75%;
}
.offset-sm-10 {
margin-left: 83.3333333333%;
}
.offset-sm-11 {
margin-left: 91.6666666667%;
}
.g-sm-0,
.gx-sm-0 {
--bs-gutter-x: 0;
}
.g-sm-0,
.gy-sm-0 {
--bs-gutter-y: 0;
}
.g-sm-1,
.gx-sm-1 {
--bs-gutter-x: 0.25rem;
}
.g-sm-1,
.gy-sm-1 {
--bs-gutter-y: 0.25rem;
}
.g-sm-2,
.gx-sm-2 {
--bs-gutter-x: 0.5rem;
}
.g-sm-2,
.gy-sm-2 {
--bs-gutter-y: 0.5rem;
}
.g-sm-3,
.gx-sm-3 {
--bs-gutter-x: 1rem;
}
.g-sm-3,
.gy-sm-3 {
--bs-gutter-y: 1rem;
}
.g-sm-4,
.gx-sm-4 {
--bs-gutter-x: 1.5rem;
}
.g-sm-4,
.gy-sm-4 {
--bs-gutter-y: 1.5rem;
}
.g-sm-5,
.gx-sm-5 {
--bs-gutter-x: 3rem;
}
.g-sm-5,
.gy-sm-5 {
--bs-gutter-y: 3rem;
}
}
bootstrap5.css
@media (min-width: 768px) {
.col-md {
flex: 1 0 0%;
}
.row-cols-md-auto > * {
flex: 0 0 auto;
width: auto;
}
.row-cols-md-1 > * {
flex: 0 0 auto;
width: 100%;
}
.row-cols-md-2 > * {
flex: 0 0 auto;
width: 50%;
}
.row-cols-md-3 > * {
flex: 0 0 auto;
width: 33.3333333333%;
}
.row-cols-md-4 > * {
flex: 0 0 auto;
width: 25%;
}
.row-cols-md-5 > * {
flex: 0 0 auto;
width: 20%;
}
.row-cols-md-6 > * {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-md-auto {
flex: 0 0 auto;
width: auto;
}
.col-md-1 {
flex: 0 0 auto;
width: 8.3333333333%;
}
.col-md-2 {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-md-3 {
flex: 0 0 auto;
width: 25%;
}
.col-md-4 {
flex: 0 0 auto;
width: 33.3333333333%;
}
.col-md-5 {
flex: 0 0 auto;
width: 41.6666666667%;
}
.col-md-6 {
flex: 0 0 auto;
width: 50%;
}
.col-md-7 {
flex: 0 0 auto;
width: 58.3333333333%;
}
.col-md-8 {
flex: 0 0 auto;
width: 66.6666666667%;
}
.col-md-9 {
flex: 0 0 auto;
width: 75%;
}
.col-md-10 {
flex: 0 0 auto;
width: 83.3333333333%;
}
.col-md-11 {
flex: 0 0 auto;
width: 91.6666666667%;
}
.col-md-12 {
flex: 0 0 auto;
width: 100%;
}
.offset-md-0 {
margin-left: 0;
}
.offset-md-1 {
margin-left: 8.3333333333%;
}
.offset-md-2 {
margin-left: 16.6666666667%;
}
.offset-md-3 {
margin-left: 25%;
}
.offset-md-4 {
margin-left: 33.3333333333%;
}
.offset-md-5 {
margin-left: 41.6666666667%;
}
.offset-md-6 {
margin-left: 50%;
}
.offset-md-7 {
margin-left: 58.3333333333%;
}
.offset-md-8 {
margin-left: 66.6666666667%;
}
.offset-md-9 {
margin-left: 75%;
}
.offset-md-10 {
margin-left: 83.3333333333%;
}
.offset-md-11 {
margin-left: 91.6666666667%;
}
.g-md-0,
.gx-md-0 {
--bs-gutter-x: 0;
}
.g-md-0,
.gy-md-0 {
--bs-gutter-y: 0;
}
.g-md-1,
.gx-md-1 {
--bs-gutter-x: 0.25rem;
}
.g-md-1,
.gy-md-1 {
--bs-gutter-y: 0.25rem;
}
.g-md-2,
.gx-md-2 {
--bs-gutter-x: 0.5rem;
}
.g-md-2,
.gy-md-2 {
--bs-gutter-y: 0.5rem;
}
.g-md-3,
.gx-md-3 {
--bs-gutter-x: 1rem;
}
.g-md-3,
.gy-md-3 {
--bs-gutter-y: 1rem;
}
.g-md-4,
.gx-md-4 {
--bs-gutter-x: 1.5rem;
}
.g-md-4,
.gy-md-4 {
--bs-gutter-y: 1.5rem;
}
.g-md-5,
.gx-md-5 {
--bs-gutter-x: 3rem;
}
.g-md-5,
.gy-md-5 {
--bs-gutter-y: 3rem;
}
}
bootstrap5.css
@media (min-width: 992px) {
.col-lg {
flex: 1 0 0%;
}
.row-cols-lg-auto > * {
flex: 0 0 auto;
width: auto;
}
.row-cols-lg-1 > * {
flex: 0 0 auto;
width: 100%;
}
.row-cols-lg-2 > * {
flex: 0 0 auto;
width: 50%;
}
.row-cols-lg-3 > * {
flex: 0 0 auto;
width: 33.3333333333%;
}
.row-cols-lg-4 > * {
flex: 0 0 auto;
width: 25%;
}
.row-cols-lg-5 > * {
flex: 0 0 auto;
width: 20%;
}
.row-cols-lg-6 > * {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-lg-auto {
flex: 0 0 auto;
width: auto;
}
.col-lg-1 {
flex: 0 0 auto;
width: 8.3333333333%;
}
.col-lg-2 {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-lg-3 {
flex: 0 0 auto;
width: 25%;
}
.col-lg-4 {
flex: 0 0 auto;
width: 33.3333333333%;
}
.col-lg-5 {
flex: 0 0 auto;
width: 41.6666666667%;
}
.col-lg-6 {
flex: 0 0 auto;
width: 50%;
}
.col-lg-7 {
flex: 0 0 auto;
width: 58.3333333333%;
}
.col-lg-8 {
flex: 0 0 auto;
width: 66.6666666667%;
}
.col-lg-9 {
flex: 0 0 auto;
width: 75%;
}
.col-lg-10 {
flex: 0 0 auto;
width: 83.3333333333%;
}
.col-lg-11 {
flex: 0 0 auto;
width: 91.6666666667%;
}
.col-lg-12 {
flex: 0 0 auto;
width: 100%;
}
.offset-lg-0 {
margin-left: 0;
}
.offset-lg-1 {
margin-left: 8.3333333333%;
}
.offset-lg-2 {
margin-left: 16.6666666667%;
}
.offset-lg-3 {
margin-left: 25%;
}
.offset-lg-4 {
margin-left: 33.3333333333%;
}
.offset-lg-5 {
margin-left: 41.6666666667%;
}
.offset-lg-6 {
margin-left: 50%;
}
.offset-lg-7 {
margin-left: 58.3333333333%;
}
.offset-lg-8 {
margin-left: 66.6666666667%;
}
.offset-lg-9 {
margin-left: 75%;
}
.offset-lg-10 {
margin-left: 83.3333333333%;
}
.offset-lg-11 {
margin-left: 91.6666666667%;
}
.g-lg-0,
.gx-lg-0 {
--bs-gutter-x: 0;
}
.g-lg-0,
.gy-lg-0 {
--bs-gutter-y: 0;
}
.g-lg-1,
.gx-lg-1 {
--bs-gutter-x: 0.25rem;
}
.g-lg-1,
.gy-lg-1 {
--bs-gutter-y: 0.25rem;
}
.g-lg-2,
.gx-lg-2 {
--bs-gutter-x: 0.5rem;
}
.g-lg-2,
.gy-lg-2 {
--bs-gutter-y: 0.5rem;
}
.g-lg-3,
.gx-lg-3 {
--bs-gutter-x: 1rem;
}
.g-lg-3,
.gy-lg-3 {
--bs-gutter-y: 1rem;
}
.g-lg-4,
.gx-lg-4 {
--bs-gutter-x: 1.5rem;
}
.g-lg-4,
.gy-lg-4 {
--bs-gutter-y: 1.5rem;
}
.g-lg-5,
.gx-lg-5 {
--bs-gutter-x: 3rem;
}
.g-lg-5,
.gy-lg-5 {
--bs-gutter-y: 3rem;
}
}
bootstrap5.css
@media (min-width: 1200px) {
.col-xl {
flex: 1 0 0%;
}
.row-cols-xl-auto > * {
flex: 0 0 auto;
width: auto;
}
.row-cols-xl-1 > * {
flex: 0 0 auto;
width: 100%;
}
.row-cols-xl-2 > * {
flex: 0 0 auto;
width: 50%;
}
.row-cols-xl-3 > * {
flex: 0 0 auto;
width: 33.3333333333%;
}
.row-cols-xl-4 > * {
flex: 0 0 auto;
width: 25%;
}
.row-cols-xl-5 > * {
flex: 0 0 auto;
width: 20%;
}
.row-cols-xl-6 > * {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-xl-auto {
flex: 0 0 auto;
width: auto;
}
.col-xl-1 {
flex: 0 0 auto;
width: 8.3333333333%;
}
.col-xl-2 {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-xl-3 {
flex: 0 0 auto;
width: 25%;
}
.col-xl-4 {
flex: 0 0 auto;
width: 33.3333333333%;
}
.col-xl-5 {
flex: 0 0 auto;
width: 41.6666666667%;
}
.col-xl-6 {
flex: 0 0 auto;
width: 50%;
}
.col-xl-7 {
flex: 0 0 auto;
width: 58.3333333333%;
}
.col-xl-8 {
flex: 0 0 auto;
width: 66.6666666667%;
}
.col-xl-9 {
flex: 0 0 auto;
width: 75%;
}
.col-xl-10 {
flex: 0 0 auto;
width: 83.3333333333%;
}
.col-xl-11 {
flex: 0 0 auto;
width: 91.6666666667%;
}
.col-xl-12 {
flex: 0 0 auto;
width: 100%;
}
.offset-xl-0 {
margin-left: 0;
}
.offset-xl-1 {
margin-left: 8.3333333333%;
}
.offset-xl-2 {
margin-left: 16.6666666667%;
}
.offset-xl-3 {
margin-left: 25%;
}
.offset-xl-4 {
margin-left: 33.3333333333%;
}
.offset-xl-5 {
margin-left: 41.6666666667%;
}
.offset-xl-6 {
margin-left: 50%;
}
.offset-xl-7 {
margin-left: 58.3333333333%;
}
.offset-xl-8 {
margin-left: 66.6666666667%;
}
.offset-xl-9 {
margin-left: 75%;
}
.offset-xl-10 {
margin-left: 83.3333333333%;
}
.offset-xl-11 {
margin-left: 91.6666666667%;
}
.g-xl-0,
.gx-xl-0 {
--bs-gutter-x: 0;
}
.g-xl-0,
.gy-xl-0 {
--bs-gutter-y: 0;
}
.g-xl-1,
.gx-xl-1 {
--bs-gutter-x: 0.25rem;
}
.g-xl-1,
.gy-xl-1 {
--bs-gutter-y: 0.25rem;
}
.g-xl-2,
.gx-xl-2 {
--bs-gutter-x: 0.5rem;
}
.g-xl-2,
.gy-xl-2 {
--bs-gutter-y: 0.5rem;
}
.g-xl-3,
.gx-xl-3 {
--bs-gutter-x: 1rem;
}
.g-xl-3,
.gy-xl-3 {
--bs-gutter-y: 1rem;
}
.g-xl-4,
.gx-xl-4 {
--bs-gutter-x: 1.5rem;
}
.g-xl-4,
.gy-xl-4 {
--bs-gutter-y: 1.5rem;
}
.g-xl-5,
.gx-xl-5 {
--bs-gutter-x: 3rem;
}
.g-xl-5,
.gy-xl-5 {
--bs-gutter-y: 3rem;
}
}
bootstrap5.css
@media (min-width: 1400px) {
.col-xxl {
flex: 1 0 0%;
}
.row-cols-xxl-auto > * {
flex: 0 0 auto;
width: auto;
}
.row-cols-xxl-1 > * {
flex: 0 0 auto;
width: 100%;
}
.row-cols-xxl-2 > * {
flex: 0 0 auto;
width: 50%;
}
.row-cols-xxl-3 > * {
flex: 0 0 auto;
width: 33.3333333333%;
}
.row-cols-xxl-4 > * {
flex: 0 0 auto;
width: 25%;
}
.row-cols-xxl-5 > * {
flex: 0 0 auto;
width: 20%;
}
.row-cols-xxl-6 > * {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-xxl-auto {
flex: 0 0 auto;
width: auto;
}
.col-xxl-1 {
flex: 0 0 auto;
width: 8.3333333333%;
}
.col-xxl-2 {
flex: 0 0 auto;
width: 16.6666666667%;
}
.col-xxl-3 {
flex: 0 0 auto;
width: 25%;
}
.col-xxl-4 {
flex: 0 0 auto;
width: 33.3333333333%;
}
.col-xxl-5 {
flex: 0 0 auto;
width: 41.6666666667%;
}
.col-xxl-6 {
flex: 0 0 auto;
width: 50%;
}
.col-xxl-7 {
flex: 0 0 auto;
width: 58.3333333333%;
}
.col-xxl-8 {
flex: 0 0 auto;
width: 66.6666666667%;
}
.col-xxl-9 {
flex: 0 0 auto;
width: 75%;
}
.col-xxl-10 {
flex: 0 0 auto;
width: 83.3333333333%;
}
.col-xxl-11 {
flex: 0 0 auto;
width: 91.6666666667%;
}
.col-xxl-12 {
flex: 0 0 auto;
width: 100%;
}
.offset-xxl-0 {
margin-left: 0;
}
.offset-xxl-1 {
margin-left: 8.3333333333%;
}
.offset-xxl-2 {
margin-left: 16.6666666667%;
}
.offset-xxl-3 {
margin-left: 25%;
}
.offset-xxl-4 {
margin-left: 33.3333333333%;
}
.offset-xxl-5 {
margin-left: 41.6666666667%;
}
.offset-xxl-6 {
margin-left: 50%;
}
.offset-xxl-7 {
margin-left: 58.3333333333%;
}
.offset-xxl-8 {
margin-left: 66.6666666667%;
}
.offset-xxl-9 {
margin-left: 75%;
}
.offset-xxl-10 {
margin-left: 83.3333333333%;
}
.offset-xxl-11 {
margin-left: 91.6666666667%;
}
.g-xxl-0,
.gx-xxl-0 {
--bs-gutter-x: 0;
}
.g-xxl-0,
.gy-xxl-0 {
--bs-gutter-y: 0;
}
.g-xxl-1,
.gx-xxl-1 {
--bs-gutter-x: 0.25rem;
}
.g-xxl-1,
.gy-xxl-1 {
--bs-gutter-y: 0.25rem;
}
.g-xxl-2,
.gx-xxl-2 {
--bs-gutter-x: 0.5rem;
}
.g-xxl-2,
.gy-xxl-2 {
--bs-gutter-y: 0.5rem;
}
.g-xxl-3,
.gx-xxl-3 {
--bs-gutter-x: 1rem;
}
.g-xxl-3,
.gy-xxl-3 {
--bs-gutter-y: 1rem;
}
.g-xxl-4,
.gx-xxl-4 {
--bs-gutter-x: 1.5rem;
}
.g-xxl-4,
.gy-xxl-4 {
--bs-gutter-y: 1.5rem;
}
.g-xxl-5,
.gx-xxl-5 {
--bs-gutter-x: 3rem;
}
.g-xxl-5,
.gy-xxl-5 {
--bs-gutter-y: 3rem;
}
}
bootstrap5.css
.col-form-label {
padding-top: calc(0.375rem + 1px);
padding-bottom: calc(0.375rem + 1px);
margin-bottom: 0;
font-size: inherit;
line-height: 1.5;
}
bootstrap5.css
.col-form-label-lg {
padding-top: calc(0.5rem + 1px);
padding-bottom: calc(0.5rem + 1px);
font-size: 1.25rem;
}
bootstrap5.css
.col-form-label-sm {
padding-top: calc(0.25rem + 1px);
padding-bottom: calc(0.25rem + 1px);
font-size: 0.875rem;
}
html bootstrap5 Sample
合計12になるようにカラムの幅を指定する:col-*
1カラムのみ幅を設定、残りは等価:col-6
可変幅カラム(コンテンツの文字数により幅が可変になる):col-auto
col
col-auto:コンテンツ文字数によってが幅が可変
col
col
col-md-auto:Medium以上でコンテンツ文字数によって幅が可変
col
<div class="row">
<div class="col">col</div>
<div class="col-auto">col-auto:コンテンツ文字数によってが幅が可変</div>
<div class="col">col</div>
</div>
<div class="row">
<div class="col">col</div>
<!-- col-mdは、Medium以上の指定方法 -->
<div class="col-md-auto">col-md-auto:Medium以上でコンテンツ文字数によって幅が可変</div>
<div class="col">col</div>
</div>
1つのrow内で12を超える場合、勝手に折り返り:col-9
ブレイクポイントによる切り替え:col-sm-8
col-sm-8
col-sm-4
col-sm
col-sm
col-sm
グリッドレイアウトのネスト(入れ子、階層化):colとrow
第1階層: col-sm-9
第2階層: col-8
第2階層: col-4
第1階層: col-sm-3
<!-- rowの幅は、ひとつ上のhtmlタグの幅に制約を受けて100%になる -->
<div class="row">
<div class="col-sm-9">第1階層: col-sm-9
<!-- 階層化colの中にrow、colの幅を基準にして12の計算が始まる -->
<div class="row">
<!-- colを2つ書くと、それぞれの画面の状況により適用されるものが変わる -->
<div class="col-8">第2階層: col-8</div>
<div class="col-4">第2階層: col-4</div>
</div>
</div>
<div class="col-sm-3">第1階層: col-sm-3</div>
</div>
rowとcolの左寄せと余白で配置:justify-content:flex-start
rowとcolの中央寄せと余白で配置:justify-content-center
col-4
col-4
<!-- 中央寄席でスタート、12の残りは勝手に余白になる -->
<div class="row justify-content-center">
<div class="col-4">col-4</div>
<div class="col-4">col-4</div>
</div>
rowとcolの右寄せと余白で配置:justify-content-end
col-4
col-4
<!-- 右寄せでスタート、12の残りは勝手に余白になる -->
<div class="row justify-content-end">
<div class="col-4">col-4</div>
<div class="col-4">col-4</div>
</div>
rowとcolの等間隔と余白で配置:justify-content-around
col-4
col-4
<!-- 中央に等間隔に配置され、残りは勝手に余白になる -->
<div class="row justify-content-around">
<div class="col-4">col-4</div>
<div class="col-4">col-4</div>
</div>
rowとcolの両端から均等と余白で配置:justify-content-between
col-4
col-4
<!-- 左右に配置され、残りは勝手に余白になる -->
<div class="row justify-content-between">
<div class="col-4">col-4</div>
<div class="col-4">col-4</div>
</div>
rowとcolの画面の状況でカラムの幅を変える、Medium以上:col-md-8
col-12とcol-md-8
col-6とcol-md-4
<div class="row">
<!-- Medium以上:だとmdが優先的に選択される -->
<!-- xl:デスクトップ PC などの大画面モニタ 1200px 以上 -->
<!-- lg:ノート PC などの省サイズモニタ 992px 以上 -->
<!-- md:タブレット端末など 768px 以上 -->
<!-- sm:スマートフォン(横持ち)など 576px 以上 -->
<!-- -:スマートフォン(縦持ち)、IoT 端末など 576px 未満 -->
<div class="col-12 col-md-8">col-12とcol-md-8</div>
<div class="col-6 col-md-4">col-6とcol-md-4</div>
</div>
rowとcolの画面の状況で変える、Medium以上:Medium以上:col-md-4
col-6とcol-md-4
col-6とcol-md-4
col-6とcol-md-4
<div class="row">
<!-- Medium以下なら、2列カラムにある-->
<div class="col-6 col-md-4">col-6とcol-md-4</div>
<div class="col-6 col-md-4">col-6とcol-md-4</div>
<div class="col-6 col-md-4">col-6とcol-md-4</div>
</div>
垂直方向のカラム間のガター、オーバーフロー処理:gy-5
p-3 border bg-light
p-3 border bg-light
p-3 border bg-light
p-3 border bg-light
<!--垂直方向のガターはページの最後にある .row の下にオーバーフローを引き起こす可能性があります。-->
<!-- container overflow-hidden で、はみ出しrow部分を無視する -->
<!-- このような場合は、.row を.overflow-hidden でラップするとも言う -->
<div class="container overflow-hidden">
<div class="row gy-5">
<div class="col-6">
<div class="p-3 border bg-light">p-3 border bg-light</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">p-3 border bg-light</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">p-3 border bg-light</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">p-3 border bg-light</div>
</div>
</div>
</div>
水平・垂直方向の同時ガター:g-2
p-3 border bg-light
p-3 border bg-light
p-3 border bg-light
p-3 border bg-light
<div class="container">
<!-- g-* クラスは水平・垂直ガターを設定する -->
<div class="row g-2">
<div class="col-6">
<div class="p-3 border bg-light">p-3 border bg-light</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">p-3 border bg-light</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">p-3 border bg-light</div>
</div>
<div class="col-6">
<div class="p-3 border bg-light">p-3 border bg-light</div>
</div>
</div>
</div>
rowとcolのガターなしカラム:g-0
rowとcolのカラムのオフセット offset-md-4
rowとcolのオフセットのリセット:offset-md-0
col-sm-5とcol-md-6
col-sm-5とoffset-sm-2とcol-md-6とoffset-md-0
<div class="row">
<div class="col-sm-5 col-md-6">col-sm-5とcol-md-6</div>
<!-- Medium以上でオフセットをクリア -->
<div class="col-sm-5 offset-sm-2 col-md-6 offset-md-0">col-sm-5とoffset-sm-2とcol-md-6とoffset-md-0</div>
</div>
グリッドレイアウトとカード→カード幅の制約が決まる:card
<div class="row">
<div class="col-sm-6">
<div class="card">
<div class="card-body">
<h4 class="card-title">カードのタイトル</h4>
<p class="card-text">カードの内容</p>
<a href="#" class="btn btn-primary">ボタン</a>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<div class="card-body">
<h4 class="card-title">カードのタイトル</h4>
<p class="card-text">カードの内容</p>
<a href="#" class="btn btn-primary">ボタン</a>
</div>
</div>
</div>
</div>
画像の左寄せ:rowとcol
カードタイトル
カード本文××××××××××××××××××××××××××××××××××××××××
Last updated 3 mins ago
<div class="card mb-3">
<div class="row g-0">
<div class="col-md-4">
<svg class="bd-placeholder-img" width="100%" height="250" xmlns="http://www.w3.org/2000/svg" role="img"
aria-label="Placeholder: Image" preserveAspectRatio="xMidYMid slice" focusable="false">
<title>Placeholder</title>
<rect width="100%" height="100%" fill="#868e96" />
<text x="50%" y="50%" fill="#dee2e6" dy=".3em">Image</text>
</svg>
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">カードタイトル</h5>
<p class="card-text">カード本文××××××××××××××××××××××××××××××××××××××××</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>
定義リスト:dlとdtとdd
- dt1
- 用語1の説明。
- 長いテキストは切り捨てて省略
- 用語2の説明。
- 用語3
-
- ネストされた用語4
- ネストされた用語4の説明
<!-- rowをcolで制御する -->
<dl class="row">
<dt class="col-sm-3">dt1</dt>
<dd class="col-sm-9">用語1の説明。</dd>
<!-- text-truncateがcolの幅で自動設定される -->
<dt class="col-sm-3 text-truncate">長いテキストは切り捨てて省略</dt>
<dd class="col-sm-9">用語2の説明。</dd>
<dt class="col-sm-3">用語3</dt>
<dd class="col-sm-9">
<dl class="row">
<dt class="col-sm-4">ネストされた用語4</dt>
<dd class="col-sm-8">ネストされた用語4の説明</dd>
</dl>
</dd>
</dl>
リストグループとタブ:list-home-listとtab
<div class="row">
<div class="col-4">
<div class="list-group" id="list-tab" role="tablist">
<a class="list-group-item list-group-item-action active" id="list-home-list" data-bs-toggle="tab"
href="#list-home" role="tab" aria-controls="list-home">Home</a>
<a class="list-group-item list-group-item-action" id="list-profile-list" data-bs-toggle="tab"
href="#list-profile" role="tab" aria-controls="list-profile">Profile</a>
<a class="list-group-item list-group-item-action" id="list-messages-list" data-bs-toggle="tab"
href="#list-messages" role="tab" aria-controls="list-messages">Messages</a>
<a class="list-group-item list-group-item-action" id="list-settings-list" data-bs-toggle="tab"
href="#list-settings" role="tab" aria-controls="list-settings">Settings</a>
</div>
</div>
<div class="col-8">
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="list-home" role="tabpanel" aria-labelledby="list-home-list">
<p>本文home</p>
</div>
<div class="tab-pane fade" id="list-profile" role="tabpanel" aria-labelledby="list-profile-list">
<p>本文profile</p>
</div>
<div class="tab-pane fade" id="list-messages" role="tabpanel" aria-labelledby="list-messages-list">
<p>本文messages</p>
</div>
<div class="tab-pane fade" id="list-settings" role="tabpanel" aria-labelledby="list-settings-list">
<p>本文settings</p>
</div>
</div>
</div>
</div>
フォームタイトルのアイコン、水平レイアウト:rowとcolとfa-shopping-basket
formタイトルにfont-awesome
<!-- https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css -->
<!-- font-awesomeによるアイコン -->
<h3 class="block-title-info">
<i class="fa fa-shopping-basket" aria-hidden="true"></i>formタイトルにfont-awesome
</h3>
<div class="row">
<!-- formのレイアウトにrowとcolを利用して、垂直から水平レイアウトに変更する -->
<!-- 最小単位のセット、勝手に順番に2列で並んでいく -->
<div class="mb-3 col-sm-6">
<label for="text4a">First name</label>
<input type="text" class="form-control" id="text4a" placeholder="First name" />
</div>
<div class="mb-3 col-sm-6">
<label for="text4b">Last name</label>
<input type="text" class="form-control" id="text4b" placeholder="Last name" />
</div>
<div class="mb-3 col-sm-6">
<label for="text4a">First name</label>
<input type="text" class="form-control" id="text4a" placeholder="First name" />
</div>
<div class="mb-3 col-sm-6">
<label for="text4b">Last name</label>
<input type="text" class="form-control" id="text4b" placeholder="Last name" />
</div>
<div class="mb-3 col-sm-6">
<label for="select1a">Select:</label>
<select id="select1a" class="form-select">
<option>Select A</option>
<option>Select B</option>
</select>
</div>
<div class="mb-3 col-sm-6">
<!-- クリックするとファイルダイヤログが表示 -->
<label for="file1">Fileを選択を開く</label>
<input type="file" id="file1" class="form-control-file" />
</div>
<div class="mb-3 col-sm-6">
<label for="select1a">check:</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="check1a" checked />
<label class="form-check-label" for="check1a">Check A</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="check1b" />
<label class="form-check-label" for="check1b">Check B</label>
</div>
</div>
<div class="mb-3 col-sm-6">
<label for="select1a">radio:</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="radio1" id="radio1a" checked />
<label class="form-check-label" for="radio1a">Check A</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="radio1" id="radio1b" />
<label class="form-check-label" for="radio1b">Check B</label>
</div>
</div>
</div>
読み取りテキストを、枠を非表示にする:form-control-plaintext
<form>
<!-- divにrowを設定して、labelとdivにcolを設定する -->
<div class="mb-3 row">
<label for="staticEmail" class="col-sm-4 col-form-label">メールアドレス</label>
<div class="col-sm-8">
<!-- inputの枠を表示しない -->
<input type="text" class="form-control-plaintext" readonly id="staticEmail" value="email@example.com">
</div>
</div>
<div class="mb-3 row">
<label for="inputPassword" class="col-sm-4 col-form-label">パスワード</label>
<div class="col-sm-8">
<!-- typeにpasswordを使うと、入力内容が*として表示される -->
<input type="password" class="form-control" id="inputPassword" placeholder="パスワードを入力">
</div>
</div>
</form>
フォームレイアウト3カラム:rowとcol
<!-- col-sm-7 のような特定のカラムクラスを使って、残りの .col が残りのスペースを均等に分割する -->
<div class="row g-3">
<div class="col-sm-7">
<input type="text" class="form-control" placeholder="住所" aria-label="住所" />
</div>
<div class="col-sm">
<input type="text" class="form-control" placeholder="マンション名" aria-label="マンション名" />
</div>
<div class="col-sm">
<input type="text" class="form-control" placeholder="部屋番号" aria-label="部屋番号" />
</div>
</div>
フォームレイアウトにrow自動サイズ調整カラム:rowとcol-auto
<!-- flexbox ユーティリティを使用してコンテンツを垂直方向にセンタリングし、 -->
<!-- .col を .col-auto に変更して、カラムが必要なだけのスペースを占有する。 -->
<!-- カラムのサイズは内容に基づいてデバイス等により自動的に決定されます -->
<!-- bootstrap5では、form-rowからrowに変更 -->
<div class="row align-items-center">
<div class="col-auto">
<!-- labelはvisually-hidden -->
<label class="visually-hidden" for="inputName">氏名</label>
<input type="text" class="form-control mb-2" id="inputName" placeholder="氏名を入力">
</div>
<div class="col-auto">
<div class="input-group mb-2">
<label class="visually-hidden" for="inputUsername">ユーザーネーム</label>
<input type="text" class="form-control" id="inputUsername" placeholder="ユーザーネームを入力">
</div>
</div>
<div class="col-auto">
<div class="form-check mb-2">
<input type="checkbox" class="form-check-input" id="check">
<label class="form-check-label" for="check"> チェックする </label>
</div>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary mb-2">送信</button>
</div>
</div>
フォームレイアウトにrow:rowとmb-3とcol-md-6
<!-- colとrowで自由自在にデザインを作っていく -->
<div class="row">
<div class="mb-3 col-md-6">
<label for="inputEmail">メールアドレス</label>
<input type="email" class="form-control" id="inputEmail" placeholder="メールアドレスを入力">
</div>
<div class="mb-3 col-md-6">
<label for="inputPassword">パスワード</label>
<input type="password" class="form-control" id="inputPassword" placeholder="パスワードを入力">
</div>
</div>
<div class="row">
<div class="mb-3 col-md-4">
<label for="inputState">国</label>
<select id="inputState" class="form-select">
<option selected>Choose...</option>
<option>...</option>
</select>
</div>
<div class="mb-3 col-md-2">
<label for="inputZip">郵便番号</label>
<input type="text" class="form-control" id="inputZip">
</div>
<div class="mb-3 col-md-6">
<label for="inputCity">都道府県</label>
<input type="text" class="form-control" id="inputCity">
</div>
</div>
<div class="mb-3">
<label for="inputAddress1">住所1</label>
<input type="text" class="form-control" id="inputAddress1" placeholder="市町村">
</div>
<div class="mb-3">
<label for="inputAddress2">住所2</label>
<input type="text" class="form-control" id="inputAddress2" placeholder="マンション名">
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="check">
<label class="form-check-label" for="check">チェックする</label>
</div>
</div>
<button type="submit" class="btn btn-primary">サインイン</button>
水平配置のフォームを作成する:mb-3とrowとcol
チェックボックス
<div class="mb-3 row">
<label for="inputEmail" class="col-sm-2 col-form-label">メールアドレス</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail" placeholder="メールアドレスを入力">
</div>
</div>
<div class="mb-3 row">
<label for="inputPassword" class="col-sm-2 col-form-label">パスワード</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword" placeholder="パスワードを入力">
</div>
</div>
<fieldset class="mb-3">
<div class="row">
<legend class="col-form-label col-sm-2 pt-0">ラジオボタン</legend>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="radio" name="radios" id="radios1" value="option1" checked>
<label class="form-check-label" for="radios1">オプション1</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="radios" id="radios2" value="option2">
<label class="form-check-label" for="radios2">オプション2</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="radios" id="radios3" value="option3" disabled>
<label class="form-check-label" for="radios3">オプション3(無効)</label>
</div>
</div>
</div>
</fieldset>
<div class="mb-3 row">
<div class="col-sm-2">チェックボックス</div>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="check1">
<label class="form-check-label" for="check1">チェックする</label>
</div>
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary">サインイン</button>
</div>
</div>
ラベルサイズを調整する:col-form-label-smとform-control-sm
<div class="mb-3 row">
<!-- 小サイズのラベル -->
<label for="labelSm" class="col-sm-3 col-form-label col-form-label-sm">小サイズ:col-form-label-sm</label>
<div class="col-sm-9">
<input type="email" class="form-control form-control-sm" id="labelSm" placeholder="form-control-sm">
</div>
</div>
<div class="mb-3 row">
<!-- 標準サイズのラベル -->
<label for="labelDefault" class="col-sm-3 col-form-label">標準サイズ</label>
<div class="col-sm-9">
<input type="email" class="form-control" id="labelDefault" placeholder="Default size">
</div>
</div>
<div class="mb-3 row">
<!-- 大サイズのラベル -->
<label for="labelLg" class="col-sm-3 col-form-label col-form-label-lg">大サイズ:col-form-label-lg</label>
<div class="col-sm-9">
<input type="email" class="form-control form-control-lg" id="labelLg" placeholder="form-control-lg">
</div>
</div>
クライアント側で入力検証を行う場合:required
市町村名を入力してください
都道府県名を入力してください
郵便番号を入力してください
<form class="row g-3">
<div class="col-md-6 mb-3">
<label for="validationServer01">姓</label>
<!-- requiredは必須-->
<input type="text" class="form-control" id="validationServer01" placeholder="First name" value="山田" required>
<div class="invalid-feedback">姓を入力してください</div>
</div>
<div class="col-md-6 mb-3">
<label for="validationServer02">名</label>
<input type="text" class="form-control" id="validationServer02" placeholder="Last name" value="太郎" required>
<div class="invalid-feedback">名を入力してください</div>
</div>
</div>
<div class="form">
<div class="col-md-6 mb-3">
<label for="validationServer03">市町村</label>
<input type="text" class="form-control" id="validationServer03" placeholder="市町村名を入力" required>
<div class="invalid-feedback">市町村名を入力してください</div>
</div>
<div class="col-md-3 mb-3">
<label for="validationServer04">都道府県</label>
<input type="text" class="form-control" id="validationServer04" placeholder="都道府県名を入力" required>
<div class="invalid-feedback">都道府県名を入力してください</div>
</div>
<div class="col-md-3 mb-3">
<label for="validationServer05">郵便番号</label>
<input type="text" class="form-control" id="validationServer05" placeholder="郵便番号を入力" required>
<div class="invalid-feedback">郵便番号を入力してください</div>
</div>
</div>
<button class="btn btn-primary" type="submit">送信する</button>
</form>
サーバー側で入力検証を行う場合:is-valid
市町村名を入力してください
都道府県名を入力してください
郵便番号を入力してください
<div class="form">
<div class="col-md-6 mb-3">
<label for="validationServer01">姓</label>
<!-- is-valid はチェックマークが付く-->
<input type="text" class="form-control is-valid" id="validationServer01" placeholder="First name" value="山田"
required>
</div>
<div class="col-md-6 mb-3">
<label for="validationServer02">名</label>
<input type="text" class="form-control is-valid" id="validationServer02" placeholder="Last name" value="太郎"
required>
</div>
</div>
<div class="form">
<div class="col-md-6 mb-3">
<label for="validationServer03">市町村</label>
<input type="text" class="form-control is-invalid" id="validationServer03" placeholder="市町村名を入力" required>
<div class="invalid-feedback">市町村名を入力してください</div>
</div>
<div class="col-md-3 mb-3">
<label for="validationServer04">都道府県</label>
<input type="text" class="form-control is-invalid" id="validationServer04" placeholder="都道府県名を入力" required>
<div class="invalid-feedback">都道府県名を入力してください</div>
</div>
<div class="col-md-3 mb-3">
<label for="validationServer05">郵便番号</label>
<input type="text" class="form-control is-invalid" id="validationServer05" placeholder="郵便番号を入力" required>
<div class="invalid-feedback">郵便番号を入力してください</div>
</div>
</div>
<button class="btn btn-primary" type="submit">送信する</button>
js Collapse (コラプス)折り畳み:collapse
a要素とhref属性によるボタン
罫線なし、色なしでやれば、リンクではなく、その下にコンテンツを出せる
a要素の切替ボタンをクリックすることで表示と非表示とが切り替わるコンテンツ
<div class="row">
<div class="col-sm-6 mb-4">
<!-- a要素とhref属性による切替ボタン -->
<p>
<a data-bs-toggle="collapse" href="#collapseContent01" aria-expanded="false" aria-controls="collapseContent01">
a要素とhref属性によるボタン<br>
罫線なし、色なしでやれば、リンクではなく、その下にコンテンツを出せる
</a>
</p>
<div class="collapse" id="collapseContent01">
<div class="card card-body">
a要素の切替ボタンをクリックすることで表示と非表示とが切り替わるコンテンツ
</div>
</div>
</div>
</div>
js 垂直方向中央に配置するモーダル:modal-dialog-centered
<div class="container">
<button type="button" class="btn btn-secondary" data-bs-toggle="modal"
data-bs-target="#exampleModal3">モーダルボタン</button>
<!-- モーダルウィンドウ外枠 id="exampleModal3"-->
<div class="modal fade" id="exampleModal3" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">モーダルのタイトル</h5>
<!-- モーダルの×ボタン -->
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
モーダルの本文が入ります。
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">閉じる</button>
</div>
</div>
</div>
</div>
</div>
<style>
.row>.col,
.row>[class^=col-] {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
background-color: f8f8ff;
border: 1px solid #aaa;
}
</style>
js グリッドレイアウトを使用したモーダル:rowとcol
<div class="container">
<button type="button" class="btn btn-secondary" data-bs-toggle="modal"
data-bs-target="#exampleModal4">モーダルボタン</button>
<!-- モーダルウィンドウ外枠 id="exampleModal4"-->
<div class="modal fade" id="exampleModal4" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">モーダルのタイトル</h5>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<!-- container-fluidは画面いっぱい -->
<div class="container-fluid">
<div class="row">
<div class="col-md-4">col-md-4</div>
<div class="col-md-4 ms-auto">col-md-4、ms-auto</div>
</div>
<div class="row">
<div class="col-md-3 ms-auto">col-md-3、ms-auto</div>
<div class="col-md-2 ms-auto">col-md-2、ms-auto</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">閉じる</button>
</div>
</div>
</div>
</div>
</div>