[英]Using Variables in PostCSS
I am having a problem creating a plugin for PostCSS . 我在为PostCSS创建插件时遇到问题。
To understand what I want to do, please take a look at the following code: 要了解我想做什么,请看以下代码:
button {
button: button;
button-border: 3px solid #abcde1;
}
Here is what I would like to do. 这是我想做的。
If button-border is NOT set, then I would like there to be a default value of: 如果未设置button-border,那么我希望有一个默认值:
border: none;
However, if button-border is set, then I would like to use the value set in button-border. 但是,如果设置了button-border,那么我想使用在button-border中设置的值。 Ini the example above that would be:
上面的例子是:
border: 3px solid #abcde1;
I thought I would do that by setting a variable, but I think I'm having problems with scope. 我以为可以通过设置变量来做到这一点,但是我认为范围存在问题。 Here is the code that I have tried:
这是我尝试过的代码:
css.walkDecls(decl => {
var buttonBorder = 'none',
button = [
'cursor: pointer;',
'display: inline-block;',
'min-height: 1em;',
'outline: none;',
'border:' + buttonBorder
],
joinButton = button.join('');
if (decl.prop === 'button-border') {
var buttonBorder = decl.value;
decl.remove();
}
if (decl.prop === 'button') {
decl.replaceWith(joinButton);
}
});
Any idea of what I am doing wrong and how I can do it right? 您对我做错了什么以及如何正确做有任何想法吗?
Thanks, 谢谢,
Moshe 摩西
Here is the answer I received at the Postcss github page: https://github.com/postcss/postcss/issues/691#issuecomment-168686832 这是我在Postcss github页面上收到的答案: https : //github.com/postcss/postcss/issues/691#issuecomment-168686832
I tried it and it works. 我试过了,它有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.