LESS 的命名空间、类捆绑的 SCSS 等价物是什么

发布于 2024-12-23 14:14:51 字数 1147 浏览 5 评论 0原文

浏览 Twitter Bootstrap 的 2.0-wip 分支,我发现 LESS 有一种很好的捆绑变量和 mixin 的方法。请参阅下面的示例代码:

#font {
  #family {
    .serif() {
      font-family: Georgia, "Times New Roman", Times, serif;
    }
    .sans-serif() {
      font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    }
    .monospace() {
      font-family: Menlo, Monaco, Courier New, monospace;
    }
  }
  .shorthand(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
    font-size: @size;
    font-weight: @weight;
    line-height: @lineHeight;
  }
  .serif(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
    #font > #family > .serif;
    #font > .shorthand(@size, @weight, @lineHeight);
  }
  .sans-serif(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
    #font > #family > .sans-serif;
    #font > .shorthand(@size, @weight, @lineHeight);
  }
  .monospace(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
    #font > #family > .monospace;
    #font > .shorthand(@size, @weight, @lineHeight);
  }
}

与之等效的 SCSS 是什么?如何在 SCSS 中重写上面的内容?

Browsing through the 2.0-wip branch of Twitter Bootstrap, I found LESS have a nice way of bundling variables and mixins. See the example code below:

#font {
  #family {
    .serif() {
      font-family: Georgia, "Times New Roman", Times, serif;
    }
    .sans-serif() {
      font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    }
    .monospace() {
      font-family: Menlo, Monaco, Courier New, monospace;
    }
  }
  .shorthand(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
    font-size: @size;
    font-weight: @weight;
    line-height: @lineHeight;
  }
  .serif(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
    #font > #family > .serif;
    #font > .shorthand(@size, @weight, @lineHeight);
  }
  .sans-serif(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
    #font > #family > .sans-serif;
    #font > .shorthand(@size, @weight, @lineHeight);
  }
  .monospace(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
    #font > #family > .monospace;
    #font > .shorthand(@size, @weight, @lineHeight);
  }
}

What is the SCSS equivalent of that? How do I re-write the above in SCSS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百善笑为先 2024-12-30 14:14:51

不幸的是,这是当今 SCSS 中缺少的功能之一(据我所知)。这个问题的答案是:没有等效的 SCSS。您必须以 SCSS 兼容的方式重新编写它。看看我在 SCSS Twitter Bootstrap fork< 中的重写内容< /a> 例如(使用您提到的例子)。

PS 不要使用那个分叉,它现在没有维护,你可能最好使用官方 Twitter Bootstrap 的 wiki 中提到的分叉。 (详细信息

Unfortunately, this is one of missing features (according to me) in SCSS today. The answer to this question is: there's is no SCSS equivalent. You have to re-write it in a SCSS compatible way. Look at my rewrite in my SCSS Twitter Bootstrap fork for example (uses the very example you mentioned).

P.S. Don't use that fork, it is not maintained right now and you're probably better off with the one mentioned in the wiki of the official Twitter Bootstrap. (details)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文