我应该使用Bootstrap辅助类和Angular材料的组件?



Bootstrap提供了很多很棒的辅助工具[像填充,或flex布局],并且只能使用它的CSS文件导入[不是js文件,它提供了所有的组件如日历等]

那么,我可以使用Bootstrap为这些助手类和Angular Material为组件吗?这是个好主意吗?我甚至可以去TailwindCSS的帮助类,而不是Bootstrap

是的,我经常用Angular Material来做组件,用Bootstrap来做布局。注意,你应该使用@ng-bootstrap/ng-bootstrap,因为正常的Bootstrap需要jQuery。

下面是我如何将两者混合在一起的一个例子:

/*-----------------------------------------------
|   Bootstrap 4 Setup
-----------------------------------------------*/
@import '~bootstrap/scss/functions';
// My custom Bootstrap overrides
@import 'theme/variables';
/*-----------------------------------------------
|   Bootstrap 4 Stylesheets
|   Comment out unused stylesheets
-----------------------------------------------*/
@import '~bootstrap/scss/variables';
@import '~bootstrap/scss/functions';
@import '~bootstrap/scss/variables';
@import '~bootstrap/scss/mixins';
@import '~bootstrap/scss/root';
@import '~bootstrap/scss/reboot';
@import '~bootstrap/scss/type';
@import '~bootstrap/scss/images';
@import '~bootstrap/scss/code';
@import '~bootstrap/scss/grid';
@import '~bootstrap/scss/tables';
@import '~bootstrap/scss/forms';
@import '~bootstrap/scss/buttons';
@import '~bootstrap/scss/transitions';
@import '~bootstrap/scss/dropdown';
@import '~bootstrap/scss/button-group';
@import '~bootstrap/scss/input-group';
@import '~bootstrap/scss/custom-forms';
@import '~bootstrap/scss/nav';
@import '~bootstrap/scss/navbar';
@import '~bootstrap/scss/card';
@import '~bootstrap/scss/breadcrumb';
@import '~bootstrap/scss/pagination';
@import '~bootstrap/scss/badge';
@import '~bootstrap/scss/jumbotron';
@import '~bootstrap/scss/alert';
@import '~bootstrap/scss/progress';
@import '~bootstrap/scss/media';
@import '~bootstrap/scss/list-group';
@import '~bootstrap/scss/close';
@import '~bootstrap/scss/toasts';
@import '~bootstrap/scss/modal';
@import '~bootstrap/scss/tooltip';
@import '~bootstrap/scss/popover';
@import '~bootstrap/scss/carousel';
@import '~bootstrap/scss/spinners';
@import '~bootstrap/scss/utilities';
@import '~bootstrap/scss/print';

/**
Angular custom theme
*/
@import '~@angular/material/theming';
@include mat-core();
$md-primary: (
50 : #e6effc,
100 : #c0d7f7,
200 : #96bdf2,
300 : #6ba3ed,
400 : #4c8fe9,
500 : #2c7be5,
600 : #2773e2,
700 : #2168de,
800 : #1b5eda,
900 : #104bd3,
A100 : #ffffff,
A200 : #cedbff,
A400 : #9bb5ff,
A700 : #81a2ff,
contrast: (
50 : #000000,
100 : #000000,
200 : #000000,
300 : #000000,
400 : #000000,
500 : #ffffff,
600 : #ffffff,
700 : #ffffff,
800 : #ffffff,
900 : #ffffff,
A100 : #000000,
A200 : #000000,
A400 : #000000,
A700 : #000000,
)
);
$md-warning: (
50 : #fef0e8,
100 : #fcd9c5,
200 : #fac09f,
300 : #f8a678,
400 : #f7935b,
500 : #f5803e,
600 : #f47838,
700 : #f26d30,
800 : #f06328,
900 : #ee501b,
A100 : #ffffff,
A200 : #fff2ee,
A400 : #ffcabb,
A700 : #ffb6a1,
contrast: (
50 : #000000,
100 : #000000,
200 : #000000,
300 : #000000,
400 : #000000,
500 : #000000,
600 : #000000,
700 : #000000,
800 : #000000,
900 : #ffffff,
A100 : #000000,
A200 : #000000,
A400 : #000000,
A700 : #000000,
)
);
$md-danger: (
50 : #fce7eb,
100 : #f8c3cd,
200 : #f39bab,
300 : #ee7389,
400 : #ea5570,
500 : #e63757,
600 : #e3314f,
700 : #df2a46,
800 : #db233c,
900 : #d5162c,
A100 : #ffffff,
A200 : #ffd3d7,
A400 : #ffa0a8,
A700 : #ff8691,
contrast: (
50 : #000000,
100 : #000000,
200 : #000000,
300 : #000000,
400 : #000000,
500 : #ffffff,
600 : #ffffff,
700 : #ffffff,
800 : #ffffff,
900 : #ffffff,
A100 : #000000,
A200 : #000000,
A400 : #000000,
A700 : #000000,
)
);
$md-secondary: (
50 : #eef0f2,
100 : #d5d9df,
200 : #bac0ca,
300 : #9ea7b4,
400 : #8994a4,
500 : #748194,
600 : #6c798c,
700 : #616e81,
800 : #576477,
900 : #445165,
A100 : #c1d9ff,
A200 : #8ebaff,
A400 : #5b9cff,
A700 : #418cff,
contrast: (
50 : #000000,
100 : #000000,
200 : #000000,
300 : #000000,
400 : #000000,
500 : #ffffff,
600 : #ffffff,
700 : #ffffff,
800 : #ffffff,
900 : #ffffff,
A100 : #000000,
A200 : #000000,
A400 : #000000,
A700 : #000000,
)
);
$default-theme-primary: mat-palette($md-primary, 500, 100, 900);
$default-theme-accent: mat-palette($md-warning, 800, 300, 200);
$default-theme-warn: mat-palette($md-danger, A700);
// create theme (use mat-dark-theme for themes with dark backgrounds)
$default-theme: mat-light-theme(
$default-theme-primary,
$default-theme-accent,
$default-theme-warn
);
$custom-typography: mat-typography-config(
$font-family: $font-family-sans-serif,
$subheading-1: mat-typography-level(19.2px, $headings-line-height, $headings-font-weight),
$subheading-2: mat-typography-level(27.648px, $headings-line-height, $headings-font-weight),
$headline: mat-typography-level(39.8131px, 24px, $headings-font-weight),
$title: mat-typography-level(33.1776px, 24px, $headings-font-weight),
$body-2: mat-typography-level(16px, 24px, 500),
$body-1: mat-typography-level(16px, 20px, 400),
$caption: mat-typography-level(14px, 20px, 400),
$button: mat-typography-level(16px, 14px, 500)
);

@include angular-material-theme($default-theme);
@include angular-material-typography($custom-typography);
/**
Custom theme files here
*/

我认为最好的选择是创建自己的flexbox和padding类。您可以从不同的MIT图书馆中获得灵感,例如:

https://www.npmjs.com/package/flexboxes

https://www.npmjs.com/package/sass-flexbox

另一方面,你使用Bootstrap和Angular Material对我来说也不坏。

最新更新