javascript - How to detect mobile notch? - Stack Overflow

I have a web app like my image 1 below, everything looks good. The problem is that when the app is laun

I have a web app like my image 1 below, everything looks good. The problem is that when the app is launched on a mobile that has a notch, it creates a layout problem, as you can see in image 2. And I can not use a "safe area" because some of my pages need to be stuck on top, like the image 3.

I can easily solve this by adding media queries to add a padding above the content on iPhone X, but the problem is that not only iPhone X have a notch.

Ideally there should be a JS method to detect mobiles with a notch (and return the height of this notch would be even better) But is this possible? If not, what is the better way to deal with this problem? Do I have to create media queries for every smartphone in the world ?

I have a web app like my image 1 below, everything looks good. The problem is that when the app is launched on a mobile that has a notch, it creates a layout problem, as you can see in image 2. And I can not use a "safe area" because some of my pages need to be stuck on top, like the image 3.

I can easily solve this by adding media queries to add a padding above the content on iPhone X, but the problem is that not only iPhone X have a notch.

Ideally there should be a JS method to detect mobiles with a notch (and return the height of this notch would be even better) But is this possible? If not, what is the better way to deal with this problem? Do I have to create media queries for every smartphone in the world ?

Share Improve this question asked Dec 14, 2018 at 4:42 ValdVald 2372 silver badges9 bronze badges 3
  • stackoverflow./questions/47226824/… – Lalji Tadhani Commented Dec 14, 2018 at 4:54
  • @LaljiTadhani I explained that I had no problem detecting an iPhone X. What I want is to detect all phones with a notch – Vald Commented Dec 14, 2018 at 4:55
  • stackoverflow./questions/46318395/… – Lalji Tadhani Commented Dec 14, 2018 at 4:58
Add a ment  | 

1 Answer 1

Reset to default 8

HTML::

meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" 

CSS::

padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744198657a4562776.html

相关推荐

  • javascript - How to detect mobile notch? - Stack Overflow

    I have a web app like my image 1 below, everything looks good. The problem is that when the app is laun

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信