Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retina iPad Specific CSS

I'm designing a responsive site that will look different on mobile devices. I have three separate media queries in my css plus a query for retina display(s).

/** 768PX IPAD PORTRAIT **/
@media screen and (max-width: 768px) {}

/** 480PX IPHONE LANDSCAPE **/
@media screen and (max-width: 480px) {}

/** 320PX PORTRAIT **/
@media screen and (max-width: 320px) {}

/**  RETINA IMAGES **/
@media all and (-webkit-min-device-pixel-ratio: 2) {}

When iPad is in portrait mode, it will get the mobile version, but when it's in landscape mode it will get the regular version of the site.

My problem is this, now with the "new iPad" and retina display, certain retina images are not aligned properly for the landscape retina iPad version. The global retina css is overruling the regular css and it's supposed to I guess.

For example, in the mobile version, I have an background image centred on the screen, but on the regular site, it's left aligned.

Anyone know of a way to target only retina images for iPad only in CSS?

Thanks

Edit: This is what I was playing around with but it doesn't seem to work:

@media screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) and (-webkit-min-device-pixel-ratio: 2) {}
like image 942
user127181 Avatar asked Mar 20 '12 01:03

user127181


People also ask

How do I target my iPad Pro CSS?

For those who want to target an iPad Pro 11" the device-width is 834px, device-height is 1194px and the device-pixel-ratio is 2. Source: screen. width , screen.

How do I change the view mode on my iPad?

Make sure that Rotation Lock is off: Swipe down from the top-right corner of your screen to open Control Center. Then tap the Rotation Lock button to make sure it's off.

What is the difference between max width and max device width?

max-width is the width of the target display area, e.g. the browser; max-device-width is the width of the device's entire rendering area, i.e. the actual device screen.

How do I use media query on all devices?

A media query consist of a media type that can contain one or more expression which can be either true or false. The result of the query is true if the specified media matches the type of device where the document is displayed on. If the media query is true then the style is applied.


3 Answers

Figured it out.

I had my iPad Retina query below all other queries but they needed to be above the other queries starting from largest to smallest.

like image 194
user127181 Avatar answered Oct 14 '22 16:10

user127181


Try:

@media only screen 
  and (min-device-width: 1536px)
  and (max-device-width: 2048px)
  and (orientation : landscape)
  and (-webkit-min-device-pixel-ratio: 2) {
      // Retina iPad specific CSS
}
like image 23
Connor Avatar answered Oct 14 '22 15:10

Connor


I had the same problem and I solved using:

@media only screen and (max-width: 960px), only screen and (max-device-width: 960px) and (-webkit-device-pixel-ratio: 1.5)

For meta viewport I use:

content="width=device-width; initial-scale=1; maximum-scale=1"

I don't know if this is a perfect solution, but it works.

like image 40
Walli Avatar answered Oct 14 '22 17:10

Walli