How to target iPhone 3GS AND iPhone 4 in one media query?

后端 未结 4 1954
天命终不由人
天命终不由人 2020-12-07 08:45

I am trying to implement alternate layouts for both the iPad/iPhone and older iPhones as well.

I have established that the best method is to use @media

4条回答
  •  心在旅途
    2020-12-07 09:06

    BoltClock's answer seems pretty good to me at the moment.

    However, thinking in to the future, if Apple (or another manufacturer) releases another device with a device pixel ratio of 2, this media query would be used for this device too.

    I don't think it's out of the question to assume that this will happen, and that the new device could have a much larger screen, such as an iPad with a retina display.

    To make this query only applicable to the iPhone 4 and previous iPhones (and any other device of a similar size)

    @media screen and (max-device-width: 480px), screen and (max-device-width: [[IPHONE_4_WIDTH]]px) and (-webkit-min-device-pixel-ratio: 2) {
        /* iPhone CSS rules here */
    }
    

    Unsure of [[IPHONE_4_WIDTH]] right now - don't have one on me, and some sites say 480, some say 960. Try replacing with both. (And let me know what you find :) )

提交回复
热议问题