title: CSS media queries, pixel density, desktop and mobile devices
body: <p><strong>Situation :</strong><br>
  I have 5 CSS files:</p>
  
  <blockquote>
    <ul>
    <li><p>base.css with some styles that apply everywhere</p></li>
    <li><p>339px.css for widths up to 339px</p></li>
    <li><p>639px.css for widths up to 639px</p></li>
    <li><p>999px.css and</p></li>
    <li><p>bigscreen.css for anything above 999px width</p></li>
    </ul>
  </blockquote>
  
  <p><strong>Code :</strong></p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" media="all" type="text/css" href="css/base.css" /&gt;
  &lt;link rel="stylesheet" type="text/css" media="screen and (min-width:    0px) and (max-width: 339px)" href="css/339px.css" /&gt;
  &lt;link rel="stylesheet" type="text/css" media="screen and (min-width:  340px) and (max-width: 639px)" href="css/639px.css" /&gt;
  &lt;link rel="stylesheet" type="text/css" media="screen and (min-width:  640px) and (max-width: 999px)" href="css/999px.css" /&gt;
  &lt;link rel="stylesheet" type="text/css" media="screen and (min-width: 1000px)" href="css/bigscreen.css" /&gt;
  </code></pre>
  
  <p>This is all well and good and performs perfectly on any device where 1 css pixel equals 1/96 inch (2.54cm) on the device screen. Recently, however, many display devices have pixel densities much higher than this, so they apply, say, the 639px.css when the 339px.css would be appropriate. This is a problem, as the contents look <strong>way</strong> too small.</p>
  
  <p>Also note that I cannot use JavaScript and desktop computers schould always get the corresponding css file according to width, regardless of orientation.</p>
  
  <p>What I am looking to achieve:</p>
  
  <ul>
  <li>339px.css for any device with:<br>
  <ul>
  <li>a width &lt;=339px</li>
  <li>a high resolution but a small screen (for instance my android smartphone with 1280x720 but a 5.7" screen) and in portrait orientation.</li>
  </ul></li>
  </ul>
  
  <p>Bascially instead of css pixel, I'd want a unit that is relative to the pixel density of the device (Desktop, tablet, smartphone, 4k displays, "Retina" displays, you get the idea) and works with all major browsers on both mobile and desktop platforms.</p>
  
  <p>At the same time, I also need a fallback to css pixels for older browsers.</p>
  
  <p>It has given me a major headache to achive this. As far as I understand, you could use the <code>device-pixel-ratio</code>, but I have not succeeded in not making the css files "overlap" at some point (an area where two css files are active, for instance 339px.css and 639px.css).</p>
  
  <p>I am at my wits end. I have tried a combination of <code>min-width</code>, <code>max-width</code>, <code>device-pixel-ratio</code>, <code>orientation: portrait/landscape</code> media query, but this failed due to the fact that desktops should ignore the orientation. So far I couldn't get a positive result across devices, even if I disregarded the browser support requirement.</p>