Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS media queries for pixel density: -moz-min-device-pixel-ratio vs. min--moz-device-pixel-ratio

When using CSS media queries for device pixel density, I have seen both -moz-min-device-pixel-ratio and min--moz-device-pixel-ratio.

For example:

@media 
  only screen and (-moz-min-device-pixel-ratio: 1.5) {
  /* styles go here */
}

vs.

@media 
  only screen and (min--moz-device-pixel-ratio: 1.5) {
  /* styles go here*/
}

Which is correct?

Some tutorials/blogs that use the former:

  • http://menacingcloud.com/?c=highPixelDensityDisplays
  • http://css3.bradshawenterprises.com/blog/retina-image-replacement-for-new-ipad/

Some tutorials/blogs that use the later, including mozilla.org:

  • http://www.slideshare.net/zomigi/css3-using-media-queries-to-improve-the-web-site-experience
  • https://developer.mozilla.org/en/CSS/Media_queries/
like image 287
Nathan Avatar asked Jul 11 '12 03:07

Nathan


People also ask

Are CSS pixels different from device pixels?

A hardware pixel is an individual dot of light in the display. A software pixel, also called a CSS pixel in the web world, is a unit of measurement. The device manufacturer determines how many hardware pixels equals one software pixel, a concept known as the device pixel ratio.

How do I find the pixel ratio of a device?

Dividing the physical ppi by the ideal ppi of 150, gives the device pixel ratio.

What is DPR device pixel ratio?

The devicePixelRatio of Window interface returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device. This value could also be interpreted as the ratio of pixel sizes: the size of one CSS pixel to the size of one physical pixel.

What is DPR in screen resolution?

Device pixel ratio (DPR) is an easy way to convert between device-independent pixels and device pixels (also called "CSS pixels"), so that high-DPR images are only delivered to devices that can support them.


2 Answers

The second one is correct.

This is from http://www.quirksmode.org/blog/archives/2012/07/vendor_prefixes.html

-webkit-min-device-pixel-ratio: 1.5
min--moz-device-pixel-ratio: 1.5
-o-min-device-pixel-ratio: 3/2
like image 183
justinavery Avatar answered Oct 28 '22 23:10

justinavery


I'm the author of the menacing cloud article referenced above. The device-pixel-ratio listed in my article was incorrect since it was written quite a while ago (iPhone4 launch).

It has been updated to reference the correct Mozilla syntax.

I have no idea why Mozilla chose to go with min--moz-device-pixel-ratio, but that is the official form chosen it seems.

like image 38
Edward Avatar answered Oct 29 '22 00:10

Edward