iPhone X / 8 / 8 Plus CSS media queries

后端 未结 5 2105
猫巷女王i
猫巷女王i 2020-12-02 05:02

What are the CSS media queries corresponding to Apple\'s new devices ? I need to set the body\'s background-color to change the X\'s safe area back

5条回答
  •  春和景丽
    2020-12-02 05:28

    I noticed that the answers here are using: device-width, device-height, min-device-width, min-device-height, max-device-width, max-device-height.

    Please refrain from using them since they are deprecated. see MDN for reference. Instead use the regular min-width, max-width and so on. For extra assurance, you can set the min and max to the same px amount. For example:

    iPhone X

    @media only screen 
        and (width : 375px) 
        and (height : 635px)
        and (orientation : portrait)  
        and (-webkit-device-pixel-ratio : 3) { }
    

    You may also notice that I am using 635px for height. Try it yourself the window height is actually 635px. run iOS simulator for iPhone X and in Safari Web inspector do window.innerHeight. Here are a few useful links on this subject:

    • https://medium.com/@hacknicity/how-ios-apps-adapt-to-the-iphone-x-screen-size-a00bd109bbb9
    • https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/
    • https://ivomynttinen.com/blog/ios-design-guidelines
    • https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

提交回复
热议问题