0

I'm trying to create a mixin guard, as seen on http://lesscss.org/features/ , where they do mixin(@a) when (@media = mobile) { ... }

However, when I do mixin() when (@media = mobile) { ... } or mixin(@a) when (@media = mobile) { ... }, less is saying it's expecting a ) at @media's @ sign and that it's expecting an "expression" at the closing ). Conversely, if I do mixin(@a) when (@a = 5) { ... }, less is happy.

Why is this, and how can I get @media to work in my mixin's guard?

mwarrior
  • 499
  • 5
  • 17
  • 1
    Note that *just* `@media` thing is a variable having nothing to do with CSS `@media ...` statement (thus `@media = mobile` tries to compare `mobile` to the value of `@media` variable to be defined elsewhere). Aside of this, you seem to want to obtain current page media state missing the fact that Less is compiled to CSS *before* this CSS can/may be applied to any page (thus Less can have *no idea* what *will* be the media in a browser somewhere *in future*). In other words and in short: it's impossible. – seven-phases-max Sep 17 '19 at 20:20
  • I.e. in a *pre*processor, if you need different code for different media, the code should appear explicitly within the corresponding `@media ... {...}` block. – seven-phases-max Sep 17 '19 at 20:25

0 Answers0