Browsers don't always compute the vh unit the same way.
Some mobile browsers compute the vh CSS unit without taking care of the url bar.
That means that a 100vh div will overflow the viewport by the size of the url bar.
This is the current behavior for:
As explained in the chrome post, that make sense but make it hard to have a full hero top block.
This script will measure the difference and put it in a CSS var.
It's doing a very good job:
https://github.com/rodneyrehm/viewport-units-buggyfill
But it has some problems with media-queries:
rodneyrehm/viewport-units-buggyfill#13
<script src="https://unpkg.com/vh-check/dist/vh-check.min.js"></script>
<script>
(function () {
// initialize the test
var isNeeded = vhCheck('vh-test');
}());
</script>npm install vh-check
var vhCheck = require('vh-check');
// isNeeded will be true || false
var isNeeded = vhCheck();npm install vh-check
import vhCheck from 'vh-check';
const isNeeded = vhCheck();- It will update the
vh-checkCSS custom property if needed vh-checkwill be updated on orientation changevh-checkwill not be updated on scroll event
You can pass the CSS var name as a param to vhCheck() (default vh-check)
vhCheck('browser-address-bar')In your CSS you will have to reference:
:root {
--browser-address-bar: 0px;
}
main {
min-height: calc(100vh - var(--browser-address-bar));
}vhCheck():root {
--vh-offset: 0px;
}
main {
/* If you need to support browser without CSS var support */
height: 100vh;
/* enable vh fix */
height: calc(100vh - var(--vh-offset));
}- vh unit – supported since IE9+
- calc – supported since IE9+
- CSS custom properties – supported since IE Edge and iOS 9.3+ IE11 & below will need a fallback without CSS var
- concerned browsers – as for now:
- Safari since iOS7+
- Chrome Android since version 56
https://hiswe.github.io/vh-check/
- clone the project
npm installnpm run demo- go to: http://localhost:8080