To overcome this issue, the solution is to incorporate viewport-fit=cover
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
While this will utilize the entire screen, what about the notch?
The approach is to create a specific class
.iphoneX{
padding: constant(safe-area-inset-top) constant(safe-area-inset-right) constant(safe-area-inset-bottom) constant(safe-area-inset-left);
}
Add this class to the website wrapper and problem solved? Not quite
Full-width images and divs with various colors may get cropped
In my case, I use <section>
for background images or colors, adding a div within the section for content. Instead of using .iphoneX
on the website wrapper, I applied .iphoneX_rl
to the div
.iphoneX_rl{
padding: 0 constant(safe-area-inset-right) 0 constant(safe-area-inset-left);
}
This covers the right and left sides, but what about the bottom?
.iphoneX_footer{
padding: 0 0 constant(safe-area-inset-bottom) 0
}
Integrate this into the last div (container) in your footer section
With these adjustments, my website displays properly on iPhone X/10. However, viewing it on an iPhone 8 pushes the content to the edges. Is it now time for js/jquery manipulation?
if (navigator.userAgent.match(/(iPhone)/)){
if((screen.availHeight == 812) && (screen.availWidth == 375)){
if((window.innerHeight == "375") && (window.innerWidth == "812")){
$('.someClass,.someClass,.someClass').addClass("iphoneX_rl");
alert("ok iphone X - L");
}else{
$('.someClass,.someClass,.someClass').removeClass("iphoneX_rl");
alert("ok iphone X - P");
}
}
}
navigator.userAgent.match(/(iPhone)/)
checks for any iPhone device
(screen.availHeight == 812) && (screen.availWidth == 375)
verifies if it's an iPhone 10
((window.innerHeight == "375") && (window.innerWidth == "812"))
detects landscape orientation
If your website utilizes Google Maps, include this class in landscape mode
$('#map_section').addClass("gm_iphoneX");
class definition:
.gm_iphoneX div.gmnoprint{
margin-right: 40px !important;
}
If there's a more efficient method or something that was overlooked, please share your insights
Thank you