如何在sass/scss中转义string css?
问题描述:
我有一个包含CSS值的字符串,我想使用它,但与gruntjs返回我一个错误如何在sass/scss中转义string css?
Syntax error: Invalid CSS after " @media ": expected media query (e.g. print, screen, print and screen), was "$from-smartphon..."
这是我的VAR
$from-smartphone-portrait: "only screen and (min-width: 1px)";
,这是我怎么称呼它:
@media $from-smartphone-portrait {
// Smartphone portrait
body {
font-size: 12px;
line-height: 14px;
}
}
在更短的
我可以在这种模式下逃避它:
@from-smartphone-portrait: ~"only screen and (min-width: 1px)";
如何在SASS/SCSS中做同样的事情?
感谢
答
您可以使用unquote
功能:
$from-smartphone-portrait: unquote("only screen and (min-width: 1px)");
要使用变量为媒查询定义:
@media #{$from-smartphone-portrait} {
同样的错误不会发生任何变化 –
我已经更新了我的答案,并更新了“$ from-smartphone-portrait”变量的调用。注意,这是从Sass版本3.2 –
工作,它工作正常,没有使用unquote是必要的这个功能? –