I have been working on making our CMS export valid content for mobile devices. One of the problems we encountered was that newer devices, like the iphone4 have a higher resolution display so we needed to find a way to render the same page correctly on older devices and newer that use a 300dpi display. So far we used javascript and window.devicePixelRatio in order to get the dpi resolution, but it turns out this is not working in opera(?) and opera mobile.
Any suggestetions or maybe a defferent approach? I researched a bit but was unable to find somethig.
Thanks
I think you might misunderstand what
devicePixelRatiois really telling you — surprise, a pixel is not a pixel!When you specify a pixel size in CSS, you’re not necessarily specifying a size in physical pixels. Instead the CSS
pxunit is actually a “device-independent pixel” (DIP), which is relative to the device’s DPI:The reference pixel is defined as 96dpi (Windows’ default DPI setting), so on your computer, it is true that 1 DIP (CSS
px) = 1 physical screen pixel. Additionally, even though older iOS devices have a physical DPI of 163, they still use 1 DIP = 1 pixel. However, on iPhone 4’s doubled resolution of 326 DPI, 1 DIP = 2 screen pixels, which is whatdevicePixelRatio = 2is telling you.Thus, speaking strictly of the difference between the iPhone 3 and iPhone 4, a HTML element with the style
{ width:100px; height:100px; }should render at roughly the same size on older devices and on the higher-DPI iPhone 4 since it rescales the pixel values.So there is no reason you sould have to use script to account for high-DPI devices; it should just work.