Trưng bày bootstrap

Tùy chỉnh Bootstrap 4 với các biến Sass tích hợp mới của chúng tôi cho các tùy chọn kiểu chung để dễ dàng thay đổi chủ đề và thành phần

Giới thiệu

Trong Bootstrap 3, chủ đề chủ yếu được điều khiển bởi các phần ghi đè biến trong LESS, CSS tùy chỉnh và biểu định kiểu chủ đề riêng biệt mà chúng tôi đã đưa vào tệp

// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
3 của mình. Với một số nỗ lực, người ta có thể thiết kế lại hoàn toàn giao diện của Bootstrap 3 mà không cần chạm vào các tệp cốt lõi. Bootstrap 4 cung cấp một cách tiếp cận quen thuộc nhưng hơi khác

Giờ đây, chủ đề được thực hiện bằng các biến Sass, bản đồ Sass và CSS tùy chỉnh. Không có biểu định kiểu chủ đề chuyên dụng nào nữa;

ngổ ngáo

Sử dụng các tệp Sass nguồn của chúng tôi để tận dụng các biến, bản đồ, mixin, v.v.

cấu trúc tệp

Bất cứ khi nào có thể, hãy tránh sửa đổi các tệp cốt lõi của Bootstrap. Đối với Sass, điều đó có nghĩa là tạo biểu định kiểu của riêng bạn, nhập Bootstrap để bạn có thể sửa đổi và mở rộng nó. Giả sử bạn đang sử dụng trình quản lý gói như npm, bạn sẽ có cấu trúc tệp trông như thế này

your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss

Nếu bạn đã tải xuống các tệp nguồn của chúng tôi và không sử dụng trình quản lý gói, bạn sẽ muốn thiết lập thủ công một cái gì đó tương tự với cấu trúc đó, giữ các tệp nguồn của Bootstrap tách biệt với các tệp nguồn của bạn

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss

nhập khẩu

Trong

// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
4 của bạn, bạn sẽ nhập các tệp Sass nguồn của Bootstrap. Bạn có hai lựa chọn. bao gồm tất cả Bootstrap hoặc chọn những phần bạn cần. Chúng tôi khuyến khích cách thứ hai, mặc dù lưu ý rằng có một số yêu cầu và sự phụ thuộc giữa các thành phần của chúng tôi. Bạn cũng sẽ cần bao gồm một số JavaScript cho các plugin của chúng tôi

// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";

Với thiết lập đó, bạn có thể bắt đầu sửa đổi bất kỳ biến Sass và bản đồ nào trong

// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
4 của mình. Bạn cũng có thể bắt đầu thêm các phần của Bootstrap vào phần
// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
6 nếu cần. Chúng tôi khuyên bạn nên sử dụng ngăn xếp nhập đầy đủ từ tệp
// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
7 của chúng tôi làm điểm xuất phát của bạn

Giá trị mặc định của biến

Mỗi biến Sass trong Bootstrap 4 bao gồm cờ

// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
8 cho phép bạn ghi đè giá trị mặc định của biến trong Sass của riêng bạn mà không cần sửa đổi mã nguồn của Bootstrap. Sao chép và dán các biến nếu cần, sửa đổi giá trị của chúng và xóa cờ
// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
8. Nếu một biến đã được gán, thì nó sẽ không được gán lại bởi các giá trị mặc định trong Bootstrap

Bạn sẽ tìm thấy danh sách đầy đủ các biến của Bootstrap trong

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
0

Ghi đè biến trong cùng một tệp Sass có thể xuất hiện trước hoặc sau các biến mặc định. Tuy nhiên, khi ghi đè lên các tệp Sass, phần ghi đè của bạn phải đến trước khi bạn nhập tệp Sass của Bootstrap

Đây là một ví dụ thay đổi

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
1 và
// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
2 khi nhập và biên dịch Bootstrap qua npm

your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
4

Lặp lại nếu cần cho bất kỳ biến nào trong Bootstrap, bao gồm các tùy chọn chung bên dưới

Bản đồ và vòng lặp

Bootstrap 4 bao gồm một số bản đồ Sass, các cặp giá trị chính giúp tạo các họ CSS liên quan dễ dàng hơn. Chúng tôi sử dụng bản đồ Sass cho màu sắc, điểm ngắt lưới và hơn thế nữa. Giống như các biến Sass, tất cả các bản đồ Sass bao gồm cờ

// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
8 và có thể được ghi đè và mở rộng

Một số bản đồ Sass của chúng tôi được hợp nhất thành những bản đồ trống theo mặc định. Điều này được thực hiện để cho phép dễ dàng mở rộng bản đồ Sass nhất định, nhưng phải trả giá bằng việc loại bỏ các vật phẩm khỏi bản đồ khó khăn hơn một chút

sửa đổi bản đồ

Để sửa đổi màu hiện có trong bản đồ

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4 của chúng tôi, hãy thêm phần sau vào tệp Sass tùy chỉnh của bạn

your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
7

Thêm vào bản đồ

Để thêm màu mới vào

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4, hãy thêm khóa và giá trị mới

your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
9

Xóa khỏi bản đồ

Để xóa màu khỏi

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4 hoặc bất kỳ bản đồ nào khác, hãy sử dụng
// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
7. Xin lưu ý rằng bạn phải chèn nó vào giữa các yêu cầu và tùy chọn của chúng tôi

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
2

Các phím bắt buộc

Bootstrap giả định sự hiện diện của một số khóa cụ thể trong bản đồ Sass khi chúng tôi sử dụng và tự mở rộng các khóa này. Khi bạn tùy chỉnh các bản đồ đi kèm, bạn có thể gặp lỗi khi sử dụng khóa của bản đồ Sass cụ thể

Ví dụ: chúng tôi sử dụng các khóa

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
8,
// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
9 và
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
40 từ
// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4 cho các liên kết, nút và trạng thái biểu mẫu. Việc thay thế các giá trị của các khóa này sẽ không có vấn đề gì, nhưng việc xóa chúng có thể gây ra sự cố biên dịch Sass. Trong những trường hợp này, bạn sẽ cần sửa đổi mã Sass sử dụng các giá trị đó

Chức năng

Bootstrap sử dụng một số chức năng Sass, nhưng chỉ một tập hợp con được áp dụng cho chủ đề chung. Chúng tôi đã bao gồm ba chức năng để nhận các giá trị từ bản đồ màu

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
7

Những thứ này cho phép bạn chọn một màu từ bản đồ Sass giống như cách bạn sử dụng biến màu từ v3

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
8

Chúng tôi cũng có một chức năng khác để lấy một mức độ màu cụ thể từ bản đồ

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4. Các giá trị mức âm sẽ làm sáng màu, trong khi các mức cao hơn sẽ tối hơn

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
0

Trong thực tế, bạn sẽ gọi hàm và truyền vào hai tham số. tên của màu từ

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4 (e. g. , chính hoặc nguy hiểm) và cấp số

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
1

Các hàm bổ sung có thể được thêm vào trong tương lai hoặc Sass tùy chỉnh của riêng bạn để tạo các hàm cấp độ cho các bản đồ Sass bổ sung hoặc thậm chí là một bản đồ chung nếu bạn muốn dài dòng hơn

Độ tương phản màu

Một chức năng bổ sung mà chúng tôi đưa vào Bootstrap là chức năng tương phản màu,

your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
44. Nó sử dụng không gian màu YIQ để tự động trả về màu tương phản sáng (
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
45) hoặc tối (
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
46) dựa trên màu cơ bản đã chỉ định. Hàm này đặc biệt hữu ích cho các mixin hoặc vòng lặp mà bạn đang tạo nhiều lớp

Ví dụ: để tạo các mẫu màu từ bản đồ

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4 của chúng tôi

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
2

Nó cũng có thể được sử dụng cho các nhu cầu tương phản một lần

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
3

Bạn cũng có thể chỉ định một màu cơ bản với các chức năng bản đồ màu của chúng tôi

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
4

tùy chọn sass

Tùy chỉnh Bootstrap 4 với tệp biến tùy chỉnh được tích hợp sẵn của chúng tôi và dễ dàng chuyển đổi các tùy chọn CSS toàn cầu với biến

your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
48 Sass mới. Ghi đè giá trị của một biến và biên dịch lại với
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
49 nếu cần

Bạn có thể tìm và tùy chỉnh các biến này cho các tùy chọn toàn cầu chính trong tệp

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
0 của Bootstrap

VariableValuesDescription
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
71
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
72 (mặc định) hoặc bất kỳ giá trị nào > 0Chỉ định giá trị bộ đệm mặc định để tạo các tiện ích bộ đệm của chúng tôi theo chương trình.
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
73
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
74 (mặc định) hoặc
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
75Bật kiểu
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
76 được xác định trước trên các thành phần khác nhau.
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
77
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
74 hoặc
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
75 (mặc định) Cho phép các kiểu
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
90 được xác định trước trên các thành phần khác nhau.
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
91
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
74 hoặc
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
75 (mặc định) Cho phép chuyển màu được xác định trước thông qua kiểu
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
94 trên các thành phần khác nhau.
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
95
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
74 (mặc định) hoặc
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
75Bật các
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
98 được xác định trước trên các thành phần khác nhau.
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
99
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
74 hoặc
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
75 (mặc định)Không dùng nữa
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
22
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
74 (mặc định) hoặc
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
75Cho phép tạo các lớp CSS cho hệ thống lưới (e. g. ,
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
25,
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
26,
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
27, v.v. ).
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
28
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
74 (mặc định) hoặc
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
75Bật dấu mũ phần tử giả trên
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
71.
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
72
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
74 (mặc định) hoặc
your-project/
├── scss
│   └── custom.scss
└── node_modules/
    └── bootstrap
        ├── js
        └── scss
75Kích hoạt các kiểu để tối ưu hóa việc in ấn

Màu

Nhiều thành phần và tiện ích khác nhau của Bootstrap được xây dựng thông qua một loạt các màu được xác định trong bản đồ Sass. Bản đồ này có thể được lặp lại trong Sass để nhanh chóng tạo ra một loạt các bộ quy tắc

Đủ màu sắc

Tất cả các màu có sẵn trong Bootstrap 4, có sẵn dưới dạng biến Sass và bản đồ Sass trong tệp

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
0. Điều này sẽ được mở rộng trong các bản phát hành nhỏ tiếp theo để thêm các sắc thái bổ sung, giống như những gì chúng tôi đã đưa vào

Đây là cách bạn có thể sử dụng chúng trong Sass của mình

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
5

Các lớp tiện ích màu cũng có sẵn để thiết lập

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
2 và
// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
1

Trong tương lai, chúng tôi sẽ hướng đến việc cung cấp bản đồ Sass và các biến cho các sắc thái của từng màu như chúng tôi đã thực hiện với các màu thang độ xám bên dưới

màu sắc chủ đề

Chúng tôi sử dụng một tập hợp con của tất cả các màu để tạo một bảng màu nhỏ hơn để tạo bảng phối màu, cũng có sẵn dưới dạng biến Sass và bản đồ Sass trong tệp

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
0 của Bootstraps

màu xám

Một tập hợp mở rộng các biến màu xám và bản đồ Sass trong

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
0 cho các sắc thái xám nhất quán trong dự án của bạn

Trong vòng ________ 50, bạn sẽ tìm thấy các biến màu Bootstrap và bản đồ Sass. Đây là một ví dụ về bản đồ

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
81 Sass

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
6

Thêm, xóa hoặc sửa đổi các giá trị trong bản đồ để cập nhật cách chúng được sử dụng trong nhiều thành phần khác. Thật không may, tại thời điểm này, không phải mọi thành phần đều sử dụng bản đồ Sass này. Các bản cập nhật trong tương lai sẽ cố gắng cải thiện điều này. Cho đến lúc đó, hãy lên kế hoạch sử dụng các biến

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
82 và bản đồ Sass này

Các thành phần

Nhiều thành phần và tiện ích của Bootstrap được xây dựng với các vòng lặp

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
83 lặp lại trên bản đồ Sass. Điều này đặc biệt hữu ích để tạo các biến thể của một thành phần bằng
// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4 của chúng tôi và tạo các biến thể đáp ứng cho từng điểm dừng. Khi bạn tùy chỉnh các bản đồ Sass này và biên dịch lại, bạn sẽ tự động thấy các thay đổi của mình được phản ánh trong các vòng lặp này

sửa đổi

Nhiều thành phần của Bootstrap được xây dựng với cách tiếp cận lớp sửa đổi cơ sở. Điều này có nghĩa là phần lớn kiểu dáng được chứa trong một lớp cơ sở (e. g. ,

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
85) trong khi các biến thể phong cách được giới hạn trong các lớp sửa đổi (e. g. ,
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
86). Các lớp công cụ sửa đổi này được xây dựng từ bản đồ
// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4 để tùy chỉnh số lượng và tên của các lớp công cụ sửa đổi của chúng tôi

Dưới đây là hai ví dụ về cách chúng tôi lặp qua bản đồ

// Custom.scss
// Option B: Include parts of Bootstrap

// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";

// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/code";
@import "../node_modules/bootstrap/scss/grid";
4 để tạo các công cụ sửa đổi cho thành phần
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
89 và tất cả các tiện ích nền
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
00 của chúng tôi

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
7

Phản ứng nhanh nhẹn

Các vòng lặp Sass này cũng không giới hạn ở các bản đồ màu. Bạn cũng có thể tạo các biến thể đáp ứng của các thành phần hoặc tiện ích của mình. Lấy ví dụ về các tiện ích căn chỉnh văn bản đáp ứng của chúng tôi, nơi chúng tôi trộn một vòng lặp

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
83 cho bản đồ
your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
02 Sass với một truy vấn phương tiện bao gồm

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
8

Nếu bạn cần sửa đổi

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
02 của mình, những thay đổi của bạn sẽ áp dụng cho tất cả các vòng lặp lặp lại trên bản đồ đó

biến CSS

Bootstrap 4 bao gồm khoảng hai chục thuộc tính tùy chỉnh CSS (biến) trong CSS được biên dịch của nó. Những thứ này cung cấp khả năng truy cập dễ dàng vào các giá trị thường được sử dụng như màu chủ đề, điểm dừng và ngăn xếp phông chữ chính của chúng tôi khi làm việc trong Trình kiểm tra của trình duyệt, hộp cát mã hoặc nguyên mẫu chung

biến có sẵn

Dưới đây là các biến chúng tôi đưa vào (lưu ý rằng ______204 là bắt buộc). Chúng nằm trong tệp

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
05 của chúng tôi

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
9

ví dụ

Các biến CSS cung cấp tính linh hoạt tương tự như các biến của Sass, nhưng không cần biên dịch trước khi được cung cấp cho trình duyệt. Ví dụ: ở đây chúng tôi đang đặt lại phông chữ và kiểu liên kết của trang bằng các biến CSS

// Custom.scss
// Option A: Include all of Bootstrap

@import "../node_modules/bootstrap/scss/bootstrap";
0

Biến điểm dừng

Mặc dù ban đầu chúng tôi đã bao gồm các điểm dừng trong các biến CSS của mình (e. g. ,

your-project/
├── scss
│   └── custom.scss
└── bootstrap/
    ├── js
    └── scss
06), chúng không được hỗ trợ trong truy vấn phương tiện, nhưng chúng vẫn có thể được sử dụng trong bộ quy tắc trong truy vấn phương tiện. Các biến điểm dừng này vẫn còn trong CSS đã biên dịch để tương thích ngược với điều kiện chúng có thể được JavaScript sử dụng.