简体   繁体   English

CSS 媒体查询不反映设备屏幕大小

[英]CSS media queries doesn't reflect the device screen size

I'm building a mobile web app and I created this media query to target phones with a lower screen height than the iPhone X+ (812px):我正在构建一个移动 web 应用程序,我创建了这个媒体查询来定位屏幕高度低于 iPhone X+ (812px) 的手机:

@media (max-height: 811px) {

}

It works perfectly on iOS devices but when I launch the app on a Huawei P30 pro, which clearly have a bigger screen than the iPhone, it enter in the above media query and the viewport height seems to be only 755px.它在 iOS 设备上完美运行,但是当我在显然比 iPhone 更大的屏幕的华为 P30 pro 上启动该应用程序时,它进入上述媒体查询并且视口高度似乎只有 755px。

Why did the Huawei, with a bigger screen, have a smaller viewport height?为什么屏幕更大的华为视口高度更小?

What can I do to target only phones that have a physically smaller screen than the iPhone X?我可以做些什么来只针对屏幕比 iPhone X 更小的手机?

You could make this change in your index.html - This is the one I would say is likely to be the issue for you您可以在您的index.html中进行此更改 - 这就是我要说的可能是您的问题

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0"/>

Or you could try this change in your CSS或者您可以在CSS中尝试此更改

@media screen and (max-device-height: 811px) {

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM