Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I escape string css in sass/scss?

Tags:

css

sass

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

like image 766
Alessandro Minoccheri Avatar asked Jan 05 '14 16:01

Alessandro Minoccheri


People also ask

What is #{} in SCSS?

is the css class selector, #{} interpolation syntax it allows the using of the variables in selectors and property names $name: foo; $attr: border; p. #{$name} { #{$attr}-color: blue; } the generated css: p.foo { border-color: blue; }

How do I override in SCSS?

Overriding the Base Styles scss . In order to override a base style file, you need to copy over the chain of files that is used to import it. $default-primary-light-color: #42bdf7; // and here!

Can I use SCSS in sass?

It makes use of semicolons and brackets like CSS (Cascaded Style Sheets). SASS and SCSS can import each other. Sass actually makes CSS more powerful with math and variable support.

Which string function is used to give quotes to the string in sass?

1. quote($string) Function: This function adds the quotes to the unquoted string and returns the quoted string.


1 Answers

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} {
like image 98
Mike Vranckx Avatar answered Oct 12 '22 17:10

Mike Vranckx