Search code examples
javascripthtmlcsssassnode-sass

How can I make use of this SCSS media variables?


I have this in my scss file:

$min-phone: 320px;

$retina-phone: #{"only screen and (min-width: #{$min-phone})"};

and have tried using it like this

p {
  @media $retina-phone {
    font-size: 12;
  }
}

But it fails while compiling the css. What am I doing wrong?


Solution

  • From your code you need to retrieve the var like you did for the other one : #{$retina-phone}

    it turns to be then :

    $min-phone: 320px;
    
    $retina-phone: #{"only screen and (min-width: #{$min-phone})"};
    
    p {
      @media #{$retina-phone} {
        font-size: 12;
      }
    }
    

    It will compile to

    @media only screen and (min-width: 320px) {
      p {
        font-size: 12;
      }
    }