You can add a custom test to Modernizr that checks this for you:
Modernizr.addTest('calcviewportunits', function(){ var computedHeight, div = document.createElement('div'); div.style.height = 'calc(10vh + 10vw)'; document.body.appendChild(div); computedHeight = window.getComputedStyle(div).height; document.body.removeChild(div); return computedHeight !== "0px"; });
Tested in Chrome 26 (returns false) and 41 (returns true). I was not sure what browsers do and do not support it, but you can simply run the following script to test it: http://jsfiddle.net/3dthsgv5/6/
This does not check only calc() , although I believe it is better to separate the problems. A separate test of calc() support is already present in Modernizr (but not in the default configuration) and can be found here: How to check if CSS calc () is accessible via JavaScript?
It is also worth noting that view units are not yet widely supported . Cases in which both calc and view units are supported but not merged are very rare.
Stephan muller
source share