LESS 的命名空间、类捆绑的 SCSS 等价物是什么
浏览 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,这是当今 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)