简体   繁体   中英

How can I escape string css in sass/scss?

I have a string that contain a css value and I want to use it but with gruntjs return me an error

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

this is my var

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

and this is how I call it:

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

in LESS I can escape it in this mode:

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

How can I make the same thing in SASS/SCSS?

Thanks

You can make use of the unquote function:

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

To use the variable for the media query definition:

@media #{$from-smartphone-portrait} {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM