@media: if samsung galaxy s4 is 1920x1080?

2019-03-14 05:26发布

问题:

<link rel="stylesheet" media="only screen and (max-width:1280px)" href="css/article1280.css">

I'm in the middle of coding my responsive CSS and I realized that the Samsung Galaxy S4 smartphone has a screen resolution of 1080x1920—my 23" monitor is 1920x1080. I've never browsed on this phone (I have an iPhone 3 with a resolution of 320x480 which is what I thought all smartphones were around, somewhere under 800 pixels wide) so I'm a bit perplexed. How am I supposed to create a mobile website for a smartphone with a screen resolution of 1080x1920?

回答1:

Galaxy S4 reports 360px x 640px to the browser

Aspect ratio is 9/16

Pixel ratio is 3

@media screen and (max-device-width: 360px)

@media screen and (-webkit-min-device-pixel-ratio: 3)

@media screen and (device-aspect-ratio: 9/16)


回答2:

Some media queries that you might find useful in this case are:

@media screen and (orientation: portrait | landscape) { ... }

@media screen and (device-aspect-ratio: #/#) { ... }

Here's a link with more info: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries



回答3:

use @media screen and (max-device-width: your dimension here).



回答4:

When designing on a GS4 it renders as a regular widescreen unless you use the viewport tag in your headers. I posted the example I use to make it responsive @ Samsung Galaxy S4 Responsive Design @media



回答5:

Make sure you have the viewport meta tag in your head section. Something like this:

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

This tells the user-agent to take into account the pixel density and rescale accordingly. So your 1080px width Samsung Galaxy S4 will act like a 360px width screen.



回答6:

Tested and working!

@media screen and (-webkit-min-device-pixel-ratio: 3.0) and (max-width: 1080px), screen and (max-width: 480px)