如何在 sass/scss 中转义字符串 css



我有一个包含css值的字符串,我想使用它,但gruntjs返回我一个错误

Syntax error: Invalid CSS after "   @media ": expected media query (e.g. print, screen, print and screen), was "$from-smartphon..."

这是我的变量

$from-smartphone-portrait:         "only screen and (min-width: 1px)";

这就是我所说的:

    @media $from-smartphone-portrait {
        // Smartphone portrait
        body {
            font-size: 12px;
            line-height: 14px;
        }
    }

在 LESS 中,我可以在这种模式下转义它:

@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} {

最新更新