由于 Bootstrap 是模块化的,另一种方法是使用 Angular Material,然后只从 Bootstrap 中挑选您真正需要的部分。
注意:无论你要导入什么,都应该先安装引导程序:
npm install bootstrap --save
并在您的全局style.scss 中导入所需的 sass 文件:
// Imports functions, variables, and mixins that are needed by other Bootstrap files
@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/mixins";
例如,您可能希望使用Bootstrap Reboot 以使所有浏览器更一致地呈现元素并遵循网络标准。
那么你只需要导入:
// Import Roboot
@import "~bootstrap/scss/reboot";
您可能也想使用Bootstrap Grid System,在这种情况下您可以进一步添加:
@import "~bootstrap/scss/grid"; // add the grid
所以你可以在你的 html 模板中使用它:
<div class="container">
<div class="row">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
</div>
您可能还想使用Bootstrap Utilities,在这种情况下还要添加:
@import "~bootstrap/scss/utilities"; // add css utilities
我的回答基于这里的详细解释:https://www.amadousall.com/the-good-parts-of-bootstrap-4-you-are-missing-in-your-angular-material-projects/