Created
April 3, 2020 22:14
-
-
Save cvan/6c022ff9b14cf8840e9d28730f75fc14 to your computer and use it in GitHub Desktop.
CSS for env(safe-area-inset-top) for iOS "Add to Homescreen" / PWA; standalone styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@supports (padding-top: constant(safe-area-inset-top)) { | |
body { | |
padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); | |
} | |
} | |
@media (display-mode: fullscreen) { | |
body { | |
padding: 0; | |
} | |
} | |
@media (display-mode: standalone) { | |
body { | |
padding: 0; | |
} | |
} | |
/* Older browsers (which don't support CSS variables) */ | |
body { | |
height: 100%; | |
} | |
/* Browsers which partially support CSS variables (iOS 11.0 – 11.2) | |
@supports (padding-top: constant(safe-area-inset-top)) { | |
body { | |
--safe-area-inset-top: constant(safe-area-inset-top); | |
height: calc(100% + var(--safe-area-inset-top)); | |
} | |
} | |
/* Adapted from https://medium.com/@draganeror/iphone-x-layout-features-with-css-environment-variables-d57423433dec */ | |
/* Browsers which fully support CSS variables (iOS 11.2+). | |
@supports (padding-top: env(safe-area-inset-top)) { | |
body { | |
--safe-area-inset-top: env(safe-area-inset-top); | |
height: calc(100% + var(--safe-area-inset-top)); | |
} | |
} | |
@media (display-mode: fullscreen) { | |
body { | |
height: 100%; | |
} | |
} | |
@media (display-mode: standalone) { | |
body { | |
height: 100%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment