Entry 06
Content clear of the notch
Use it on fixed headers, bottom bars, toasts and sheets in anything that should feel like an app on a phone. Add viewport-fit=cover to the viewport meta tag, then pad those elements by the safe-area insets.
Code
.app-header { padding-block-start: env(safe-area-inset-top, 0px); }
.bottom-bar { padding-block-end: env(safe-area-inset-bottom, 0px); }
.sheet { padding-block-end: calc(1rem + env(safe-area-inset-bottom, 0px)); }Why it works, the rules and the credits
Why it works
- By default the browser keeps the page inside the safe area and leaves the notch and home-indicator zones as bare background.
viewport-fit=coverlets the page paint edge to edge. env(safe-area-inset-*)gives the size of each zone, so the content moves clear while the background still fills the screen.
Rules
- Without
viewport-fit=coverevery inset is0pxand the padding does nothing. - Give
env()a fallback of0pxwherever it sits insidecalc(). - Normal page content needs none of this. The header's padding covers it.
Support
- Chrome
- 69
- Firefox
- 65
- Safari
- 11.1
Credits
Borrowed from: Emil Kowalski, mobile-native skill