Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone X / 8 / 8 Plus CSS media queries

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 background color.

like image 880
nathan Avatar asked Sep 20 '17 05:09

nathan


People also ask

What is media query for Iphone X?

Media query is a CSS technique introduced in CSS3. It is a cool way to target different screen sizes, orientations, and devices.

Can you use media queries in CSS?

Media queries are used for the following: To conditionally apply styles with the CSS @media and @import at-rules. To target specific media for the <style> , <link> , <source> , and other HTML elements with the media= attribute.

What does @media in CSS mean?

The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the content is being used.


1 Answers

iPhone X

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

iPhone 8

@media only screen      and (device-width : 375px)      and (device-height : 667px)      and (-webkit-device-pixel-ratio : 2) { } 

iPhone 8 Plus

@media only screen      and (device-width : 414px)      and (device-height : 736px)      and (-webkit-device-pixel-ratio : 3) { } 


iPhone 6+/6s+/7+/8+ share the same sizes, while the iPhone 7/8 also do.


Looking for a specific orientation ?

Portrait

Add the following rule:

    and (orientation : portrait)  

Landscape

Add the following rule:

    and (orientation : landscape)  



References:

  • https://webkit.org/blog/7929/designing-websites-for-iphone-x/
  • https://developer.apple.com/ios/human-interface-guidelines/visual-design/adaptivity-and-layout/
  • https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/
  • https://mydevice.io/devices/
  • http://viewportsizes.com/mine/
like image 78
nathan Avatar answered Sep 28 '22 02:09

nathan