Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use DPI in css media queries instead of px

Tags:

Number of pixels width and height does not always tell the whole story. That works great for adding or removing items from the screen, but isn't quite right for setting the right image. With the retina display on the MBP, a browser window set to half of the screen would have the same number of pixels in width as most machines today. Yet, images displayed would likely be too small given the higher DPI.

Is there a way to change out images based on DPI rather than the number of pixels width and height?

like image 647
Dennis Burton Avatar asked Jul 30 '12 13:07

Dennis Burton


People also ask

How do you write different resolutions in CSS?

With media queries you can set differents css rules based on screen (or media) resolution (width, height, aspect-ratio...) in a single file, or you can include different stylesheet based on the query. I suggest you to follow a tutorial to start using media queries.

How do you write a media query for maximum and minimum width?

If you want to include both min and max width for responsiveness in the browser, then you can use the following: @media (min-width: 768px) and (max-width: 992px){...} @media (min-width: 480px) and (max-width: 767px) {...}

What is Dppx CSS?

dppx. Represents the number of dots per px unit. Due to the 1:96 fixed ratio of CSS in to CSS px , 1dppx is equivalent to 96dpi , which corresponds to the default resolution of images displayed in CSS as defined by image-resolution . x. Alias for dppx .

Are CSS pixels real pixels?

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.


1 Answers

You can do either:

<link     rel="stylesheet"     type="text/css"     href="/css/retina.css"     media="only screen and (-moz-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)" /> 

or

@media only screen and (-moz-min-device-pixel-ratio: 2),         only screen and (-o-min-device-pixel-ratio: 2/1),         only screen and (-webkit-min-device-pixel-ratio: 2),         only screen and (min-device-pixel-ratio: 2) {  /*use CSS to swap out your low res images with high res ones here*/ }    
like image 101
Moin Zaman Avatar answered Oct 25 '22 10:10

Moin Zaman