[英]Media query not works on chrome emulator but not on actual screen
I have a weird issue. 我有一个奇怪的问题。
I created a media query for screen height 768px. 我为屏幕高度768px创建了一个媒体查询。 When I open chrome dev tools -> emulator and set the resolution to 1366 X 768 it works as expected. 当我打开Chrome开发工具->模拟器并将分辨率设置为1366 X 768时,它可以按预期工作。
When I close the dev tools I can see the media query css didn't apply. 当我关闭开发工具时,我可以看到媒体查询CSS并不适用。
I opened the console and checked: screen.height, screen.width, screen.availHeight and screen.availWidth. 我打开控制台并检查:screen.height,screen.width,screen.availHeight和screen.availWidth。
Both heights returned 768, both width returned 1366. 两个高度都返回768,两个宽度都返回1366。
What can be the issue? 可能是什么问题?
The media query is as follows: 媒体查询如下:
@media screen and (height: 768px)
I think the issue is that the query you are using does't matching with the corresponding device/media you are testing. 我认为问题在于您使用的查询与您要测试的相应设备/媒体不匹配。
To check whether your query applies you can check with the mediaMatch
api: 要检查您的查询是否适用,您可以使用mediaMatch
api进行检查:
Assuming you're query was something like this: 假设您要查询的内容是这样的:
window.matchMedia("(min-width: 768)").matches
This returns a boolean
. 这将返回一个boolean
。 You can check what mediaMatch
returns for your specific usecase. 您可以检查针对特定用例返回的mediaMatch
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.