Safari + CSS: using "calc" with "vh" does not work

jdotjdot picture jdotjdot · Aug 27, 2014 · Viewed 27.1k times · Source

I'm encountering a very niche issue CSS issue on Safari.

I have the following CSS rule:

min-height: calc(100vh - 115.5px - 25px*2);

This works on Chrome, but Safari doesn't seem to like the combination of calc and vh. (It works if I replace vh with %, for example--but I do need to calculate based on vh or some appropriate alternative.)

Is there some way around this to make this work? Alternatively, is there another way to refer to vh that is calc-friendly on Safari?

Answer

DragonKnight picture DragonKnight · Mar 12, 2015

before you use vw or vh, you should define:

html {
    width: 100%;
    height: 100%;
}
body {
    width: 100%;
    height: 100%;
}

and make sure you use spaces between + and - as you did.