The new vw
(and vh
, vmin
and vmax
) CSS units are quite useful, as is calc
. Both work fine in Chrome (the latter prefixed as -webkit-calc
), but for some reason I've found that calc
property values including the v*
units, such as width: -webkit-calc(95vw - 25em)
yield an invalid property value. Is this just not implemented yet, or the spec, or a bug?
Asked
Active
Viewed 1.7k times
20

Stephan Muller
- 27,018
- 16
- 85
- 126
-
1The spec allows `vw` in `calc`, it’s even used in an example there: http://www.w3.org/TR/css3-values/#calc – Jukka K. Korpela Jan 06 '13 at 14:26
-
3This was a bug in Chrome, but it's been fixed now – Stephan Muller Sep 20 '14 at 11:28
2 Answers
25
It’s a bug, registered as Bug 94158 - calc isn't working with viewport units.

Jukka K. Korpela
- 195,524
- 37
- 270
- 390
-
Is the bug fixed? I have to use it, or an alternative, and I can't find another way to do it... – Thomas Ayoub Oct 27 '13 at 16:33
-
@Samoth Not as far as I know. In Chrome 31.0.1650.57 m, and I just ran into this issue. – Blieque Nov 25 '13 at 18:00
-
Correct, this chrome bug is still a bug and is currently not being addressed. – runspired Dec 02 '13 at 04:24
-
Looks like this was stealth-fixed - at least it seems to be working in the dev channel for me. – Tom Carrick Jan 23 '14 at 10:55
-
1is this still a problem, how come `height: calc(10000vw / 25vh)` returns zero height? – oldboy Aug 29 '21 at 13:45
6
It's an old bug and has long been fixed, but if you're still supporting older versions of chrome, and specifically encountering this bug in an older version of chromium in an Android tablet you're supporting (as was my case), here's the simple way you can get around this bug:
Use a wrapper that spans the VW you're targeting, and then instead of using the viewport units in the calc(...), use 100%.
html:
<div class="container">
<div class="inner-calc-with-viewport-units-bugged" />
</div>
css:
.container {
width: 100vw; //or height: 100vh, depending on your usecase
}
.inner-calc-with-viewport-units-bugged {
width: calc(100% - XXXXX px); //or height: calc(100% - XXpx);
}

kevin
- 114
- 2
- 5
-
According to the current [w3schools tutorial](https://www.w3schools.com/cssref/func_calc.asp) that would have to be `XXXXXpx`. – Mike O'Connor Mar 03 '19 at 04:45