【问题标题】:How to use Bootstrap 4 media breakpoints in SASS? [duplicate]如何在 SASS 中使用 Bootstrap 4 媒体断点? [复制]
【发布时间】:2017-11-13 19:54:42
【问题描述】:

在官方bootstrap website 上写着:

由于我们在 Sass 中编写源 CSS,我们所有的媒体查询都是 可通过 Sass mixins 获得:

@include media-breakpoint-up(xs) { ... }
@include media-breakpoint-up(sm) { ... }
@include media-breakpoint-up(md) { ... }
@include media-breakpoint-up(lg) { ... }
@include media-breakpoint-up(xl) { ... }

// Example usage:
@include media-breakpoint-up(sm) {
  .some-class {
    display: block;
  }
}

现在,我将 SASS 用于我的 CSS,并且我也在使用 Bootstrap,但我只是通过将它们包含在 HTML 中来将两者结合起来。

当我尝试在我的 SASS 文件中做这样的事情时:

@include media-breakpoint-up(xl) { ... }

我收到一个错误:

未定义的混音

我猜这是因为我的 SASS 文件不知道 Bootstrap,因为我只在 HTML 中包含了 Bootstrap。

如何将 Bootstrap 4 作为部分文件包含到我的 SASS 文件中? (我想这是我必须要做的……)

PS:我使用的是 Bootstrap 4,我更喜欢不需要 Bower 或 RubyGems 等的解决方案,而只是下载 Bootstrap 文件并以老式方式将其包含到我的 SASS 中 - 如果可以的话全部?

【问题讨论】:

  • 你必须@import 'file_with_mixin_definitions.scss';,然后你才能使用@include
  • 谢谢,我明白了。但是我在哪里可以找到 bootstrap 4 的这些 mixin 定义?
  • 迟到但刚刚遇到这个问题,通过导入解决了它:'~bootstrap/scss/functions'; '~bootstrap/scss/变量'; '~bootstrap/scss/mixins/breakpoints';
  • 遵循@bilcker 的建议更完整的答案:stackoverflow.com/a/68114046/3009639

标签: html css twitter-bootstrap sass bootstrap-4


【解决方案1】:

下载整个源代码,并查看 scss/mixins。 _breakpoints.scss 文件是您应该拥有的文件。我做同样的事情,我下载源代码并将我需要的东西包含在我自己编译的 css 中。

@import "_variables";
@import "_mixins";
@import "_grid";

【讨论】:

  • 或@import "~bootstrap/scss/bootstrap-grid.scss"; :)
  • 另外,如果您选择使用哪些导入,请确保首先导入网格,然后您自己的覆盖。使用 SCSS 之前需要导入一些东西,然后需要导入一些东西 - 在这种情况下,顺序很重要。
猜你喜欢
  • 2017-11-21
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-09
  • 1970-01-01
  • 1970-01-01
  • 2020-02-21
  • 1970-01-01
相关资源
最近更新 更多