在我的SCSS文件中使用Bootstrap的实用程序API
Bootstrap文档说明对于一个自定义引导程序的情况。
我正在从a MT-N1 )。我想通过Mixin(或类似的东西)将它们导入我的SCSS文件中。 “ stricility api>” m不确定如何从我的SCSS文件中调用它。
我该怎么做?
例如:
// Import bootstrap
@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/mixins";
@import "~bootstrap/scss/utilities";
// Generate negative margin from $utilities:"negative-margin"
// ... <--- What goes here?
我尝试了@include generate-utity(“负微粒”)
,但失败了。
The Bootstrap documentation explains how to enable negative margins, but that is for the case where one customises Bootstrap.
I'm using it from a CDN, but I still want those classes (e.g., mt-n1
). I'd like to import them via a mixin (or something like that) into my SCSS file. The "Utility API" shows that is possible, but I'm unsure how to invoke it from my SCSS file.
How do I do that?
For example:
// Import bootstrap
@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/mixins";
@import "~bootstrap/scss/utilities";
// Generate negative margin from $utilities:"negative-margin"
// ... <--- What goes here?
I tried @include generate-utility("negative-margin")
but that failed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将Bootstrap 5变量设置
$ enable-congative-margins
true
,然后在variables.scss.scss
include之前插入它。然后,删除所有实用程序,仅包括您想要的公司,请参见示例:
You have to set the Bootstrap 5 variable
$enable-negative-margins
totrue
and insert it beforevariables.scss
include.Then, remove all utilities, and include only ones you want, see example:
Output:
我在我的自定义CSS内容中添加了常规
MT-1
等。您确实有一个基于Node.js的构建环境的前端,我建议Yaroslavtrach的答案,因为它为每个断点添加了类。
YaroslavTrach's answer is the best approach, but for those who don't use SCSS, or don't have a Node.js-based build environment in their project, here's a workaround I had been using:
I added the regular
mt-1
, etc. classes to my custom CSS content, and modified their names and values:Again, if you do have a Node.js-based build environment for your frontend, I recommend YaroslavTrach's answer as it adds classes for every breakpoint.