0

Using calc() in a media query in Chrome (version 68) seems to replace viewport units with px. Eg

@media only screen and (min-height: calc(100vw + 10px))

results in

@media only screen and (min-height: 110px)

Firefox handles it correctly and IE, Edge and Safari which doesn't support calc() in media queries (according to mozilla) seems to ignore the query which is better for my use case.

How can I apply the media query + calc() in the browsers that properly supports it? Should I expect Firefox to continue supporting calc() this way?

Use case: In a game on a square canvas that fills the viewport, a signature should appear in the lower right corner of either the canvas (default) or the viewport depending on the available space.

Demo: https://codepen.io/LoveF/pen/PBjXwr

Love
  • 1,709
  • 2
  • 22
  • 30
  • Are you sure it's Chrome doing that and not sass? – Heretic Monkey Jul 25 '18 at 15:35
  • Appear to be a bug in Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=421909 ... and this question cover that so might be a dupe: https://stackoverflow.com/questions/23667208/calc-not-working-within-media-queries – Asons Jul 25 '18 at 15:58
  • @HereticMonkey, considering that it works in Firefox, I would say it is Chrome that is faulty. Also codepen can display the compiled css and it looks fine to me: `calc(100vh - 50px + 2 * (2 * 18px + 100px))` – Love Jul 25 '18 at 17:43
  • @LGSon, I too think it is a bug. The unfortunate result is that Chrome does a miscalculation rather then to fallback to the default such as IE, Edge and Safari does, which would have been better. Maybe they will fix it but what to do until then? I also saw [that question](https://stackoverflow.com/questions/23667208/calc-not-working-within-media-queries), I think it is related but not a duplicate as `calc(2000px - 1px)` gives the correct result. – Love Jul 25 '18 at 18:21
  • @Love I would go for https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia – Asons Jul 25 '18 at 19:36

0 Answers0