Lề và đệm
Chỉ định các giá trị margin
hoặc padding
thân thiện với một phần tử hoặc một tập hợp con của các cạnh của nó với các lớp tốc ký. Bao gồm hỗ trợ cho các thuộc tính riêng lẻ, tất cả các thuộc tính, và các thuộc tính dọc và ngang. Các lớp được xây dựng từ bản đồ SASS mặc định từ .25rem
đến 3rem
.
Sử dụng mô -đun bố cục lưới CSS? Xem xét sử dụng tiện ích khoảng cách.
Ký hiệu
Các tiện ích khoảng cách áp dụng cho tất cả các điểm dừng, từ ____10 đến
Centered element
1, không có chữ viết tắt điểm dừng trong chúng. Điều này là do các lớp đó được áp dụng từ
Centered element
2 trở lên, và do đó không bị ràng buộc bởi một truy vấn truyền thông. Tuy nhiên, các điểm dừng còn lại bao gồm viết tắt điểm dừng.Các lớp được đặt tên bằng định dạng
Centered element
3 cho
Centered element
0 và
Centered element
5 cho
Centered element
6,
Centered element
7,
Centered element
8,
Centered element
9 và
Centered element
1.Nơi tài sản là một trong số:
1 - Đối với các lớp đặt.mt-n1 { margin-top: -0.25rem !important; }
margin
3 - Đối với các lớp đặt.mt-n1 { margin-top: -0.25rem !important; }
padding
Đâu là một trong những:
5 - Đối với các lớp đặt.mt-n1 { margin-top: -0.25rem !important; }
6 hoặc.mt-n1 { margin-top: -0.25rem !important; }
7.mt-n1 { margin-top: -0.25rem !important; }
8 - Đối với các lớp đặt.mt-n1 { margin-top: -0.25rem !important; }
9 hoặc.mt-n1 { margin-top: -0.25rem !important; }
0Grid item 1 Grid item 2 Grid item 3
1 - [bắt đầu] cho các lớp đặtGrid item 1 Grid item 2 Grid item 3
2 hoặcGrid item 1 Grid item 2 Grid item 3
3 trong LTR,Grid item 1 Grid item 2 Grid item 3
4 hoặcGrid item 1 Grid item 2 Grid item 3
5 trong RTLGrid item 1 Grid item 2 Grid item 3
6 - [kết thúc] cho các lớp đặtGrid item 1 Grid item 2 Grid item 3
4 hoặcGrid item 1 Grid item 2 Grid item 3
5 trong LTR,Grid item 1 Grid item 2 Grid item 3
2 hoặcGrid item 1 Grid item 2 Grid item 3
3 trong RTLGrid item 1 Grid item 2 Grid item 3
1 - Đối với các lớp đặt cả$spacer: 1rem; $spacers: [ 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, ]; $negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
2 và$spacer: 1rem; $spacers: [ 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, ]; $negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
3$spacer: 1rem; $spacers: [ 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, ]; $negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
4 - Đối với các lớp đặt cả$spacer: 1rem; $spacers: [ 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, ]; $negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
5 và$spacer: 1rem; $spacers: [ 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, ]; $negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
6$spacer: 1rem; $spacers: [ 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, ]; $negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
- trống - cho các lớp đặt
margin
hoặcpadding
ở cả 4 mặt của phần tử
Kích thước là một trong những:
9 - Đối với các lớp loại bỏ$spacer: 1rem; $spacers: [ 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, ]; $negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
margin
hoặcpadding
bằng cách đặt nó thành
9$spacer: 1rem; $spacers: [ 0: 0, 1: $spacer * .25, 2: $spacer * .5, 3: $spacer, 4: $spacer * 1.5, 5: $spacer * 3, ]; $negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
3 - [theo mặc định] cho các lớp đặt"margin": [ responsive: true, property: margin, class: m, values: map-merge[$spacers, [auto: auto]] ], "margin-x": [ responsive: true, property: margin-right margin-left, class: mx, values: map-merge[$spacers, [auto: auto]] ], "margin-y": [ responsive: true, property: margin-top margin-bottom, class: my, values: map-merge[$spacers, [auto: auto]] ], "margin-top": [ responsive: true, property: margin-top, class: mt, values: map-merge[$spacers, [auto: auto]] ], "margin-end": [ responsive: true, property: margin-right, class: me, values: map-merge[$spacers, [auto: auto]] ], "margin-bottom": [ responsive: true, property: margin-bottom, class: mb, values: map-merge[$spacers, [auto: auto]] ], "margin-start": [ responsive: true, property: margin-left, class: ms, values: map-merge[$spacers, [auto: auto]] ], // Negative margin utilities "negative-margin": [ responsive: true, property: margin, class: m, values: $negative-spacers ], "negative-margin-x": [ responsive: true, property: margin-right margin-left, class: mx, values: $negative-spacers ], "negative-margin-y": [ responsive: true, property: margin-top margin-bottom, class: my, values: $negative-spacers ], "negative-margin-top": [ responsive: true, property: margin-top, class: mt, values: $negative-spacers ], "negative-margin-end": [ responsive: true, property: margin-right, class: me, values: $negative-spacers ], "negative-margin-bottom": [ responsive: true, property: margin-bottom, class: mb, values: $negative-spacers ], "negative-margin-start": [ responsive: true, property: margin-left, class: ms, values: $negative-spacers ], // Padding utilities "padding": [ responsive: true, property: padding, class: p, values: $spacers ], "padding-x": [ responsive: true, property: padding-right padding-left, class: px, values: $spacers ], "padding-y": [ responsive: true, property: padding-top padding-bottom, class: py, values: $spacers ], "padding-top": [ responsive: true, property: padding-top, class: pt, values: $spacers ], "padding-end": [ responsive: true, property: padding-right, class: pe, values: $spacers ], "padding-bottom": [ responsive: true, property: padding-bottom, class: pb, values: $spacers ], "padding-start": [ responsive: true, property: padding-left, class: ps, values: $spacers ],
margin
hoặcpadding
thành
6"margin": [ responsive: true, property: margin, class: m, values: map-merge[$spacers, [auto: auto]] ], "margin-x": [ responsive: true, property: margin-right margin-left, class: mx, values: map-merge[$spacers, [auto: auto]] ], "margin-y": [ responsive: true, property: margin-top margin-bottom, class: my, values: map-merge[$spacers, [auto: auto]] ], "margin-top": [ responsive: true, property: margin-top, class: mt, values: map-merge[$spacers, [auto: auto]] ], "margin-end": [ responsive: true, property: margin-right, class: me, values: map-merge[$spacers, [auto: auto]] ], "margin-bottom": [ responsive: true, property: margin-bottom, class: mb, values: map-merge[$spacers, [auto: auto]] ], "margin-start": [ responsive: true, property: margin-left, class: ms, values: map-merge[$spacers, [auto: auto]] ], // Negative margin utilities "negative-margin": [ responsive: true, property: margin, class: m, values: $negative-spacers ], "negative-margin-x": [ responsive: true, property: margin-right margin-left, class: mx, values: $negative-spacers ], "negative-margin-y": [ responsive: true, property: margin-top margin-bottom, class: my, values: $negative-spacers ], "negative-margin-top": [ responsive: true, property: margin-top, class: mt, values: $negative-spacers ], "negative-margin-end": [ responsive: true, property: margin-right, class: me, values: $negative-spacers ], "negative-margin-bottom": [ responsive: true, property: margin-bottom, class: mb, values: $negative-spacers ], "negative-margin-start": [ responsive: true, property: margin-left, class: ms, values: $negative-spacers ], // Padding utilities "padding": [ responsive: true, property: padding, class: p, values: $spacers ], "padding-x": [ responsive: true, property: padding-right padding-left, class: px, values: $spacers ], "padding-y": [ responsive: true, property: padding-top padding-bottom, class: py, values: $spacers ], "padding-top": [ responsive: true, property: padding-top, class: pt, values: $spacers ], "padding-end": [ responsive: true, property: padding-right, class: pe, values: $spacers ], "padding-bottom": [ responsive: true, property: padding-bottom, class: pb, values: $spacers ], "padding-start": [ responsive: true, property: padding-left, class: ps, values: $spacers ],
7 - [theo mặc định] cho các lớp đặt"margin": [ responsive: true, property: margin, class: m, values: map-merge[$spacers, [auto: auto]] ], "margin-x": [ responsive: true, property: margin-right margin-left, class: mx, values: map-merge[$spacers, [auto: auto]] ], "margin-y": [ responsive: true, property: margin-top margin-bottom, class: my, values: map-merge[$spacers, [auto: auto]] ], "margin-top": [ responsive: true, property: margin-top, class: mt, values: map-merge[$spacers, [auto: auto]] ], "margin-end": [ responsive: true, property: margin-right, class: me, values: map-merge[$spacers, [auto: auto]] ], "margin-bottom": [ responsive: true, property: margin-bottom, class: mb, values: map-merge[$spacers, [auto: auto]] ], "margin-start": [ responsive: true, property: margin-left, class: ms, values: map-merge[$spacers, [auto: auto]] ], // Negative margin utilities "negative-margin": [ responsive: true, property: margin, class: m, values: $negative-spacers ], "negative-margin-x": [ responsive: true, property: margin-right margin-left, class: mx, values: $negative-spacers ], "negative-margin-y": [ responsive: true, property: margin-top margin-bottom, class: my, values: $negative-spacers ], "negative-margin-top": [ responsive: true, property: margin-top, class: mt, values: $negative-spacers ], "negative-margin-end": [ responsive: true, property: margin-right, class: me, values: $negative-spacers ], "negative-margin-bottom": [ responsive: true, property: margin-bottom, class: mb, values: $negative-spacers ], "negative-margin-start": [ responsive: true, property: margin-left, class: ms, values: $negative-spacers ], // Padding utilities "padding": [ responsive: true, property: padding, class: p, values: $spacers ], "padding-x": [ responsive: true, property: padding-right padding-left, class: px, values: $spacers ], "padding-y": [ responsive: true, property: padding-top padding-bottom, class: py, values: $spacers ], "padding-top": [ responsive: true, property: padding-top, class: pt, values: $spacers ], "padding-end": [ responsive: true, property: padding-right, class: pe, values: $spacers ], "padding-bottom": [ responsive: true, property: padding-bottom, class: pb, values: $spacers ], "padding-start": [ responsive: true, property: padding-left, class: ps, values: $spacers ],
margin
hoặcpadding
thànhmargin
0margin
1 - [theo mặc định] cho các lớp đặtmargin
hoặcpadding
thànhmargin
4margin
5 - [theo mặc định] cho các lớp đặtmargin
hoặcpadding
thànhmargin
8margin
9 - [theo mặc định] cho các lớp đặtmargin
hoặcpadding
thànhpadding
2padding
3 - Đối với các lớp đặtmargin
thành tự động
[Bạn có thể thêm nhiều kích thước hơn bằng cách thêm các mục vào biến bản đồ SASS padding
5.]
Ví dụ
Dưới đây là một số ví dụ đại diện của các lớp sau:
.mt-0 {
margin-top: 0 !important;
}
.ms-1 {
margin-left: [$spacer * .25] !important;
}
.px-2 {
padding-left: [$spacer * .5] !important;
padding-right: [$spacer * .5] !important;
}
.p-3 {
padding: $spacer !important;
}
Định tâm ngang
Ngoài ra, Bootstrap cũng bao gồm một lớp padding
6 cho nội dung cấp khối có chiều rộng cố định theo chiều ngang, đó là nội dung có padding
7 và padding
8 đặt bằng cách đặt lề ngang thành padding
3.
Centered element
Biên độ âm
Trong CSS, các thuộc tính margin
có thể sử dụng các giá trị âm [padding
không thể]. Các lề âm này bị vô hiệu hóa theo mặc định, nhưng có thể được bật trong SASS bằng cách đặt .25rem
2.disabled by default, but can be enabled in Sass by setting .25rem
2.
Cú pháp gần giống như các tiện ích ký quỹ mặc định, dương, nhưng với việc bổ sung .25rem
3 trước kích thước được yêu cầu. Ở đây, một lớp ví dụ mà đối lập với .25rem
4:
.mt-n1 {
margin-top: -0.25rem !important;
}
Khoảng cách
Khi sử dụng .25rem
5, bạn có thể sử dụng các tiện ích .25rem
6 trên thùng chứa lưới mẹ. Điều này có thể tiết kiệm khi phải thêm các tiện ích ký quỹ vào các mặt hàng lưới riêng lẻ [trẻ em của container .25rem
5]. Các tiện ích GAP được đáp ứng theo mặc định và được tạo thông qua API tiện ích của chúng tôi, dựa trên bản đồ SASS padding
5.
Mục lưới 1
Lưới vật phẩm 2
Lưới vật phẩm 3
Grid item 1
Grid item 2
Grid item 3
Hỗ trợ bao gồm các tùy chọn đáp ứng cho tất cả các điểm dừng lưới Bootstrap, cũng như sáu kích thước từ bản đồ padding
5 [________ 49, ____________ 69]. Không có lớp tiện ích 3rem
2 vì nó có hiệu quả giống như 3rem
3.
Sass
Bản đồ
Các tiện ích khoảng cách được khai báo thông qua SASS MAP và sau đó được tạo với API tiện ích của chúng tôi.
$spacer: 1rem;
$spacers: [
0: 0,
1: $spacer * .25,
2: $spacer * .5,
3: $spacer,
4: $spacer * 1.5,
5: $spacer * 3,
];
$negative-spacers: if[$enable-negative-margins, negativify-map[$spacers], null];
API tiện ích
Các tiện ích khoảng cách được khai báo trong API tiện ích của chúng tôi trong 3rem
4. Tìm hiểu cách sử dụng API Tiện ích.
"margin": [
responsive: true,
property: margin,
class: m,
values: map-merge[$spacers, [auto: auto]]
],
"margin-x": [
responsive: true,
property: margin-right margin-left,
class: mx,
values: map-merge[$spacers, [auto: auto]]
],
"margin-y": [
responsive: true,
property: margin-top margin-bottom,
class: my,
values: map-merge[$spacers, [auto: auto]]
],
"margin-top": [
responsive: true,
property: margin-top,
class: mt,
values: map-merge[$spacers, [auto: auto]]
],
"margin-end": [
responsive: true,
property: margin-right,
class: me,
values: map-merge[$spacers, [auto: auto]]
],
"margin-bottom": [
responsive: true,
property: margin-bottom,
class: mb,
values: map-merge[$spacers, [auto: auto]]
],
"margin-start": [
responsive: true,
property: margin-left,
class: ms,
values: map-merge[$spacers, [auto: auto]]
],
// Negative margin utilities
"negative-margin": [
responsive: true,
property: margin,
class: m,
values: $negative-spacers
],
"negative-margin-x": [
responsive: true,
property: margin-right margin-left,
class: mx,
values: $negative-spacers
],
"negative-margin-y": [
responsive: true,
property: margin-top margin-bottom,
class: my,
values: $negative-spacers
],
"negative-margin-top": [
responsive: true,
property: margin-top,
class: mt,
values: $negative-spacers
],
"negative-margin-end": [
responsive: true,
property: margin-right,
class: me,
values: $negative-spacers
],
"negative-margin-bottom": [
responsive: true,
property: margin-bottom,
class: mb,
values: $negative-spacers
],
"negative-margin-start": [
responsive: true,
property: margin-left,
class: ms,
values: $negative-spacers
],
// Padding utilities
"padding": [
responsive: true,
property: padding,
class: p,
values: $spacers
],
"padding-x": [
responsive: true,
property: padding-right padding-left,
class: px,
values: $spacers
],
"padding-y": [
responsive: true,
property: padding-top padding-bottom,
class: py,
values: $spacers
],
"padding-top": [
responsive: true,
property: padding-top,
class: pt,
values: $spacers
],
"padding-end": [
responsive: true,
property: padding-right,
class: pe,
values: $spacers
],
"padding-bottom": [
responsive: true,
property: padding-bottom,
class: pb,
values: $spacers
],
"padding-start": [
responsive: true,
property: padding-left,
class: ps,
values: $spacers
],