SASS/SCSS:在不使用中间变量的情况下引用属性
是否可以在不引入中间变量的情况下引用先前在选择器中定义的属性?
我想说的是:
.foo {
padding: 15px;
width: 300px - $padding;
}
我知道 $padding 在语法上查找已定义的变量,我仅在上面的示例中使用它来说明我想要实现的功能。
上面的例子相当于:
.foo {
$padding: 15px;
padding: $padding;
width: 300px - $padding * 2;
}
Is it possible to refer to a property previously defined in a selector without introducing an intermediate variable?
I'd like to say something like:
.foo {
padding: 15px;
width: 300px - $padding;
}
I know that $padding syntactically looks for a defined variable, I only use it in the above example to illustrate what I want to achieve in functionality.
The above example would be equivalent to this:
.foo {
$padding: 15px;
padding: $padding;
width: 300px - $padding * 2;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,你不能,但那会很棒。
我还没有测试过,但据我所知,唯一可以做到这一点的 CSS 预处理器是 stylus。查看其文档中的变量部分,其中显示属性查找。它是这样工作的:
但是不,在 Sass 中你不能,就我而言。
No, you can't, and it would be great.
I haven't tested, but as far as I know the only css pre-processor that can do that is stylus. Look at the variable section in its documentation, where it says Property Lookup. It works that way:
But no, in Sass you can't, as far as I'm concerned.
如果可以选择使用其他预处理器然后使用 scss,我强烈建议使用 Stylus。有一个名为 属性查找 的功能,这正是您想要的。
If its an option to use an other preprocessor then scss, I really recommend using Stylus. There is a feature called Property lookup which is exactly what you want.