SASS/SCSS:在不使用中间变量的情况下引用属性 [英] SASS/SCSS: Refer to property without using an intermediate variable
问题描述
是否可以在不引入中间变量的情况下引用之前在选择器中定义的属性?
Is it possible to refer to a property previously defined in a selector without introducing an intermediate variable?
我想说:
.foo {
padding: 15px;
width: 300px - $padding;
}
我知道 $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;
}
推荐答案
不,你不能,而且会很棒.
No, you can't, and it would be great.
我还没有测试过,但据我所知,唯一可以做到这一点的 css 预处理器是 stylus.查看其文档中的变量部分,其中写着属性查找.它是这样工作的:
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:
.foo {
padding: 15px;
width: 300px - @padding * 2;
}
但不,在 Sass 中你不能,就我而言.
But no, in Sass you can't, as far as I'm concerned.
这篇关于SASS/SCSS:在不使用中间变量的情况下引用属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!