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

标签 css sass

我有一个包含 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} {

关于css - 如何在 sass/scss 中转义字符串 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20935792/

相关文章:

html - pos :relative & overflow-y:scroll 内的固定位置 div

css - CodeIgniter CSS 文件

css - 如何让一个 block 出现在reactjs中?

css - SCSS 中的背景转换不起作用

html - 递归 Angular 搞乱CSS

javascript - 在图像中滑动 - JQuery

html - 在子元素上应用父样式

css - Google Pixel C 设备用户界面不会根据 CSS 选择器更改为横向模式

javascript - 自定义 Reactjs Checkbox 组件需要动态颜色

javascript - 升级 EaselJS 后自定义光标不工作