Search code examples
cssmedia-queries

iphone/ipad media query issues


I had a concern. I'm putting together a little site and for some reason my iphone and ipad media queries are colliding. The Iphone picks up on Ipad styles, but not vice versa. So I wanted to put what I'm using out there and see if anyone can help.

thanks guys.

@media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) //iphone
@media screen and (max-device-width: 480px) and (orientation:landscape) //iphone landscape
@media screen and (max-device-width: 1024px) and (orientation:landscape) //ipad landscape
@media screen and (max-device-width: 768px) and (orientation:portrait) //ipad portrait

I pulled these from a few tutorials that seemed pretty legit, any ideas why the styles are leaking?


Solution

  • You're using max-device-width which will include iphone as well. Should be:

    @media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) //iphone
    @media screen and (max-device-width: 480px) and (orientation:landscape) //iphone landscape
    @media screen and (min-device-width: 1024px) and (orientation:landscape) //ipad landscape
    @media screen and (min-device-width: 768px) and (orientation:portrait) //ipad portrait
    

    notice the min-device-width