Spacing
Spacing(スペーシング)は margin , padding を簡単に適用できます。
How it works
margin
や padding
を要素に簡略なクラスで適用できます。クラスは, .25rem
から 3rem
までのデフォルトのSassマップから構築されています。
Notation
xs
から xl
までの全てのブレークポイントに適用される空白ユーティリティには, ブレークポイントの省略形がありません。
min-width:0
以上から適用され, メディアクエリにバインドされていないためです。
クラス名は, xsの場合は, .{property}{sides}-{size}
の形式で指定し, sm
, md
, lg
, xl
の場合は, {property}{sides}-{breakpoint}-{size}
の形式で指定します。
propertyの設定
m
- for classes that setmargin
p
- for classes that setpadding
sidesの設定
t
- for classes that setmargin-top
orpadding-top
b
- for classes that setmargin-bottom
orpadding-bottom
l
- for classes that setmargin-left
orpadding-left
r
- for classes that setmargin-right
orpadding-right
x
- for classes that set both*-left
and*-right
y
- for classes that set both*-top
and*-bottom
- blank - for classes that set a
margin
orpadding
on all 4 sides of the element
sizeの設定
0
- for classes that eliminate themargin
orpadding
by setting it to0
1
- (by default) for classes that set themargin
orpadding
to$spacer * .25
2
- (by default) for classes that set themargin
orpadding
to$spacer * .5
3
- (by default) for classes that set themargin
orpadding
to$spacer
4
- (by default) for classes that set themargin
orpadding
to$spacer * 1.5
5
- (by default) for classes that set themargin
orpadding
to$spacer * 3
auto
- for classes that set themargin
to auto
$spacer
の基準値は1rem=16px。$spacers
Sassマップ変数にエントリを追加することで, さらにサイズの追加が可能です。
Examples
代表的な例を下記に表示します。
.mt-0 {
margin-top: 0 !important;
}
.ml-1 {
margin-left: ($spacer * .25) !important;
}
.px-2 {
padding-left: ($spacer * .5) !important;
padding-right: ($spacer * .5) !important;
}
.p-3 {
padding: $spacer !important;
}
Horizontal centering
固定幅のブロックレベルのコンテンツを水平にセンタリングするための .mx-auto
があります。
Centered element
<div class="mx-auto" style="width: 200px;">
Centered element
</div>
Negative margin
CSSでは, margin
プロパティはマイナスの値が利用可能です。(padding ではできません)
下記に例を示します。
.mt-n1 {
margin-top: -0.25rem !important;
}
下記は md
のブレークポイント以上にカスタマイズする例です。
.col
のパディングを .px-md-5
で増やし, 親要素 .row の .mx-md-n5
でそれを打ち消します。
Custom column padding
Custom column padding
<div class="row mx-md-n5">
<div class="col py-3 px-md-5 border bg-light">Custom column padding</div>
<div class="col py-3 px-md-5 border bg-light">Custom column padding</div>
</div>
v4.2