I am using the media query in css to differentiate iphone and ipad
Here's my code:
/* iphone 3 */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation:portrait) { ... }
/* iphone 4 */
@media only screen and (min-device-width : 640px) and (max-device-width : 960px) and (orientation:portrait) { ... }
/*iPad styles*/
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:portrait) { ... }
/* i have the same for landscape */
Now I have a resolution conflict, the iphone 4 use the same resolution as the ipad and vice versa.
How can I fix this?
Check out http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
I have tried this link http://jsfiddle.net/andresilich/SpbC3/4/show/ in the responsive test tool like http://mattkersley.com/responsive/ and
http://ipadpeek.com
.I have seen the landscape and the portrait mode displaying the same view. Is there any problem with those tools?Modify your iPhone 4 media query to target high density pixel displays (retina = iPhone4)
Didn't notice you reopened the question with an expansion so here is a reworked answer to target both iphones (3 and 4) and ipads.
Breakdown of what you should expect:
teal
background color.orange
on an ipad (landscape).black
on an ipad (portrait)red
on an iphone 4 (portrait)pink
on an iphone 4 (landscape)green
on regular smartphones, e.g Androids (landscape)purple
on a regular smartphone (portrait)CSS
I reformatted the
@media
queries found in this fine article over at CSS-tricks to comply to some iphone4-specific bits, but overall this media query set should cover both iphones (3 and 4 with separate media queries) and ipads as well.Here is a demo you can try in your i-devices.
http://jsfiddle.net/andresilich/SpbC3/4/show/
And you can also try out the queries over at http://quirktools.com/screenfly/ to see how they stack up. One thing though, the screenfly site does not differentiate between iphone 3 and 4 because regular browsers skip the
webkit
only-webkit-min-device-pixel-ratio : 1.5
pixel ratio count so you will get better results testing it out in your actual device.Great answer on using the colors to detect device and orientation. iPhone 4 did not work though and only rendered as either green or purple backgrounds.
I found this article which shed some light. http://www.hemmachat.com/2011/04/21/iphone-website-for-good-beginnings/
Now using the pixel ratio of 2 instead I can now get red and brown on an iPhone 4.
iOS does not currently support
orientation:portrait
andorientation:landscape
.Instead Apple currently uses the following:
Portrait
orientation:0
orientation:180 (not currently supported on iphone)
Landscape
orientation:90
orientation:-90
Ref: http://developer.apple.com/library/safari/#documentation/DataManagement/Reference/DOMWindowAdditionsReference/DOMWindowAdditions/DOMWindowAdditions.html