Bootstrap4モバイルフレンドリーの為の<要素の表示/非表示>

要素の表示/非表示

デバイスごとに要素を表示および非表示にするためのレスポンシブ表示クラスを使用できるようになりました。同じサイトの全く異なるバージョンを作成するのではなく、代わりに各画面サイズに応じて要素を非表示にする。

画面サイズ クラス
全て非表示 .d-none
xsのみ非表示 .d-none.d-sm-block
smのみ非表示 .d-sm-none.d-md-block
mdのみ非表示 .d-md-none.d-lg-block
lgのみ非表示 .d-lg-none.d-xl-block
xlのみ非表示 .d-xl-none
全て表示 .d-block
xsのみ表示 .d-block.d-sm-none
smのみ表示 .d-none.d-sm-block.d-md-none
mdのみ表示 .d-none.d-md-block.d-lg-none
lgのみ表示 .d-none.d-lg-block.d-xl-none
xlのみ表示 .d-none.d-xl-block

クラスの組み合わせ

{display} は、blockinlineinline-blocktabletable-celltable-rowflexinline-flex のいずれかを入れる。

クラス 極小
縦向きモバイル
<576px

横向きモバイル
(≥576px – <768px)

タブレット
(≥768px – <992px)

デスクトップ
(≥992px – <1200px)
特大
ワイド・デスクトップ
(≥1200px)
.d-{display} [表示] [表示] [表示] [表示] [表示]
.d-none [非表示] [非表示] [非表示] [非表示] [非表示]
.d-{display}.d-sm-none [表示] [非表示] [非表示] [非表示] [非表示]
.d-{display}.d-md-none [表示] [表示] [非表示] [非表示] [非表示]
.d-{display}.d-lg-none [表示] [表示] [表示] [非表示] [非表示]
.d-{display}.d-xl-none [表示] [表示] [表示] [表示] [非表示]
.d-none.d-sm-{display} [非表示] [表示] [表示] [表示] [表示]
.d-none.d-md-{display} [非表示] [非表示] [表示] [表示] [表示]
.d-none.d-lg-{display} [非表示] [非表示] [非表示] [表示] [表示]
.d-none.d-xl-{display} [非表示] [非表示] [非表示] [非表示] [表示]
.d-none.d-sm-{display}.d-md-none [非表示] [表示] [非表示] [非表示] [非表示]
.d-none.d-md-{display}.d-lg-none [非表示] [非表示] [表示] [非表示] [非表示]
.d-none.d-lg-{display}.d-xl-none [非表示] [非表示] [非表示] [表示] [非表示]
.d-none.d-sm-{display}.d-lg-none [非表示] [表示] [表示] [非表示] [非表示]
.d-none.d-sm-{display}.d-xl-none [非表示] [表示] [表示] [表示] [非表示]
.d-{display}.d-sm-none.d-md-{display} [表示] [非表示] [表示] [表示] [表示]
.d-{display}.d-sm-none.d-lg-{display} [表示] [非表示] [非表示] [表示] [表示]
.d-{display}.d-sm-none.d-xl-{display} [表示] [非表示] [非表示] [非表示] [表示]
.d-none.d-md-{display}.d-xl-none [非表示] [非表示] [表示] [表示] [非表示]
.d-{display}.d-md-none.d-lg-{display} [表示] [表示] [非表示] [表示] [表示]
.d-{display}.d-md-none.d-xl-{display} [表示] [表示] [非表示] [非表示] [表示]
.d-{display}.d-lg-none.d-xl-{display} [表示] [表示] [表示] [非表示] [表示]
クラス 極小
<576px

≥576px – <768px

≥768px – <992px

≥992px – <1200px
特大
≥1200px
.d-{display}.d-sm-none.d-md-{display}.d-lg-none [表示] [非表示] [表示] [非表示] [非表示]
.d-{display}.d-sm-none.d-md-{display}.d-xl-none [表示] [非表示] [表示] [表示] [非表示]
.d-{display}.d-sm-none.d-lg-{display}.d-xl-none [表示] [非表示] [非表示] [表示] [非表示]
.d-none.d-sm-{display}.d-md-none.d-lg-{display} [非表示] [表示] [非表示] [表示] [表示]
.d-none.d-sm-{display}.d-md-none.d-xl-{display} [非表示] [表示] [非表示] [非表示] [表示]
.d-none.d-sm-{display}.d-lg-none.d-xl-{display} [非表示] [表示] [表示] [非表示] [表示]
.d-{display}.d-md-none.d-lg-{display}.d-xl-none [表示] [表示] [非表示] [表示] [非表示]
.d-none.d-md-{display}.d-lg-none.d-xl-{display} [非表示] [非表示] [表示] [非表示] [表示]
.d-{display}.d-sm-none.d-md-{display}.d-lg-none.d-xl-{display} [表示] [非表示] [表示] [非表示] [表示]
.d-none.d-sm-{display}.d-md-none.d-lg-{display}.d-xl-none [非表示] [表示] [非表示] [表示] [非表示]

<例>タブレットを分岐にする場合

タブレットから表示/スマホ非表示
768~(大きい画面のみ表示したい要素)・・・d-none d-md-block

タブレットから非表示/スマホ表示
~767(小さい画面のみ表示したい要素)・・・d-block d-md-none

※他に使うプログラムのブレークポイントは767に設定

<例>細かく分岐する場合

xsのみ表示(576px未満) .d-block.d-sm-none
smのみ表示(576px以上768未満) .d-none.d-sm-block.d-md-none
mdのみ表示(768px以上992px未満) .d-none.d-md-block.d-lg-none
lgのみ表示(992px以上1200px未満) .d-none.d-lg-block.d-xl-none
xlのみ表示(1200px以上) .d-none.d-xl-block

コメント

タイトルとURLをコピーしました