【问题标题】:Chrome emulator not the same as iPhone - better emulator?Chrome 模拟器与 iPhone 不同 - 更好的模拟器?
【发布时间】:2016-07-03 14:28:46
【问题描述】:

我正在构建一个移动网站,但我没有让它响应。我正在为每个设备使用媒体查询。您可能认为这是一个好主意,也可能不认为这是一个好主意,但我想这样做,因为该网站只有 3 页,而且非常小,只能通过手机访问。

我的问题是我需要一个好的模拟器,以便我可以针对我不拥有的手机进行调整。我只有一部 iPhone 要测试,而 Chrome 不匹配。有没有更好的模拟器,还是我做错了什么?

Chrome version

Actual screenshot from iPhone

谢谢。

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

【问题讨论】:

  • 您正在为现有的每台设备使用单独的媒体查询?但是有成千上万。停下来做正确的事。
  • 您在文档的head 上有这个&lt;meta name=viewport content="width=device-width, initial-scale=1"&gt; 吗?因为 Chrome 设备模拟器非常适合我
  • 澄清@AlonEitan 的评论 - 推荐的&lt;meta&gt; 要求设备根据其实际像素宽度而不是像素密度呈现网站,这有时会导致网站加载你被缩小了。

标签: html css google-chrome mobile emulation


【解决方案1】:

我已经解决了这个问题。我使用以下代码从 index.html 重定向:

if (screen.width < 765) {
            window.location = "http://www.myaddress.com/index2.html";
        }

删除此代码并将 index.html 设为移动网站索引文件后,chrome 模拟器与实际屏幕相同。

我不知道为什么会这样。不知何故,使用 javascript 重定向使重定向的地址具有不同的视口。

【讨论】:

    【解决方案2】:

    你的 CSS 表在哪里?将所有这些添加到底部

    /* Smartphones (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 320px) 
    and (max-device-width : 480px) {
    /* Styles */
    }
    
    /* Smartphones (landscape) ----------- */
    @media only screen 
    and (min-width : 321px) {
    /* Styles */
    }
    
    /* Smartphones (portrait) ----------- */
    @media only screen 
    and (max-width : 320px) {
    /* Styles */
    }
    
    /* iPads (portrait and landscape) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) {
    /* Styles */
    }
    
    /* iPads (landscape) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : landscape) {
    /* Styles */
    }
    
    /* iPads (portrait) ----------- */
    @media only screen 
    and (min-device-width : 768px) 
    and (max-device-width : 1024px) 
    and (orientation : portrait) {
    /* Styles */
    }
    
    /* Desktops and laptops ----------- */
    @media only screen 
    and (min-width : 1224px) {
    /* Styles */
    }
    
    /* Large screens ----------- */
    @media only screen 
    and (min-width : 1824px) {
    /* Styles */
    }
    
    /* iPhone 4 ----------- */
    @media
    only screen and (-webkit-min-device-pixel-ratio : 1.5),
    only screen and (min-device-pixel-ratio : 1.5) {
    /* Styles */
    }
    /* iPhone 6 landscape */
    @media only screen and (min-device-width: 375px)
      and (max-device-width: 667px)
      and (orientation: landscape)
      and (-webkit-min-device-pixel-ratio: 2)
    { }
    
    /* iPhone 6 portrait */
    @media only screen
      and (min-device-width: 375px)
      and (max-device-width: 667px)
      and (orientation: portrait)
      and (-webkit-min-device-pixel-ratio: 2)
    { }
    
    /* iPhone 6 Plus landscape */
    @media only screen
      and (min-device-width: 414px)
      and (max-device-width: 736px)
      and (orientation: landscape)
      and (-webkit-min-device-pixel-ratio: 3)
    { }
    
    /* iPhone 6 Plus portrait */
    @media only screen 
      and (min-device-width: 414px) 
      and (max-device-width: 736px) 
      and (orientation: portrait) 
      and (-webkit-min-device-pixel-ratio: 3)
    { }
    
    /* iPhone 6 and 6 Plus */
    @media only screen
      and (max-device-width: 640px),
      only screen and (max-device-width: 667px),
      only screen and (max-width: 480px)
    { }
    
    /* Apple Watch */
    @media
      (max-device-width: 42mm)
      and (min-device-width: 38mm)
    { }

    【讨论】:

    • 当你可以让你的布局只使用几个断点时,为什么会有这么多特定设备的媒体查询?没有意义...
    • 我的样式表与问题有什么关系?为什么 Chrome 没有像我在手机上查看它那样模拟我的样式表?就是那个问题。 @Matti 休息一下。你要不要回答这个问题,不然就这样吧。
    • @Benjamin:有时正确的答案是“你做错了”。
    • 那些媒体查询可以满足所有当前的设备,这就是为什么要添加少量代码以确保您的网站可以在有人试图从中查看的任何设备上运行
    • @MattiVirkkunen 我的 iPhone 6 与 Chrome 的 iPhone 6 仿真不同。告诉我为什么,我会花几个小时学习如何编写响应式代码。
    猜你喜欢
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-07
    • 2011-01-04
    相关资源
    最近更新 更多