1

I have a media query in LESS: @media (max-width: 1079px) { ... }. Basically I want to create a variable in LESS in which I can just say @media (*LESS variable goes here*) { ... } in my stylesheets. How can I interpolate the string max-width: 1079px into a LESS variable to make this happen?

Thanks

jtarr523
  • 261
  • 1
  • 5
  • 16
  • possible duplicate of [Fancy Media Queries with some LESS Magic](http://stackoverflow.com/questions/15837808/fancy-media-queries-with-some-less-magic) – seven-phases-max Apr 13 '15 at 19:56

1 Answers1

1

For the variable, you could escape the string value:

@media-max-width: ~"max-width: 1079px";

Code snippet:

@media-max-width: ~"max-width: 1079px";

@media (@media-max-width) {
  p {
    color: #f00;
  }
}

Which will output the following:

@media (max-width: 1079px) {
  p {
    color: #f00;
  }
}

You could also include the parenthesis in the variable too:

@media-max-width: ~"(max-width: 1079px)";

@media @media-max-width {
  p {
    color: #f00;
  }
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304