简体   繁体   English

@media 查询在 Chrome 中运行良好,但在移动设备上无法运行

[英]@media query works fine in Chrome, but not working on mobile

I made an app by React.我用 React 做了一个应用程序。 Everything is fine on laptop Chrome.笔记本电脑 Chrome 上一切正常。 But When I checked on my phone, @media query is not working.但是当我检查我的手机时,@media 查询不起作用。 I read almost all questions and answers on stackoverflow.我几乎阅读了有关 stackoverflow 的所有问题和答案。 I could not find solution.我找不到解决方案。

<meta name="viewport" content="width=device-width,initial-scale=1">

and exapmle of my code和我的代码示例

.home-wrapper {
  position: relative;
  width:1366px;
}
@media screen and (max-width: 400px){
  .home-wrapper {
    width:375px;
}

Could you help me?你可以帮帮我吗? Thanks.谢谢。

It is most likely your phone is wider than 400px therefore doesn't enter the media query condition.很可能您的手机宽度超过400px ,因此没有进入媒体查询条件。

You can achieve what you want without using media queries, just using max-width with width like this:您可以在不使用媒体查询的情况下实现您想要的,只需使用带有width max-width ,如下所示:

 .home-wrapper { position: relative; max-width:1366px; width: 100%; /*or another value you want here like 90% or 90vw */ /* just for demo */ height: 200px; background: lightblue }
 <div class="home-wrapper"></div>

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

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