title: Em-Based CSS Media Query Showing Smaller Resolution Than Expected On Ios Mobile Safari
body: <p>I'm working on a <a href="http://staging.anti-exe.com" rel="nofollow noreferrer">new website</a> using em-based CSS media queries.  In the past, I've always used px-based media queries.  I wanted to try something new.  I have things set up in such a fashion that most phones (in portrait), most phones (in landscape) and tablets (in portrait), and most tablets (in landscape) will see differences in the layout.</p>
  
  <p>Everything works, as expected, on desktop browsers (IE, Firefox, Chrome), Android (Android browser, Chrome), and Windows Phone (IE).  iOS (Safari) displays the portrait version, as expected, but switching to landscape keeps the portrait layout.  This has been tested on an iPhone 5 (iOS7), iPad 2 (iOS7), and iPhone 4s (iOS6) and they are all consistently inconsistent.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;meta name="viewport" content="width=device-width"&gt;
  </code></pre>
  
  <p>CSS:</p>
  
  <pre><code>/* portrait phone (&lt; 480px) */
  @media screen and (max-width:29.9999em) {
  }
  
  /* landscape phone and portrait tablet (&gt;= 480px &lt; 960px) */
  @media screen and (min-width:30em) and (max-width:59.9999em) {
  }
  
  /* landscape tablet and normal monitor (&gt;= 960px &lt; 1440px) */
  @media screen and (min-width:60em) and (max-width:89.9999em) {
  }
  
  /* bigger monitor (&gt;= 1440px) */
  @media screen and (min-width:90em) {
  }
  
  /* big monitor (&gt;= 1920px) */
  @media screen and (min-width:120em) {
  }
  </code></pre>
  
  <p>So, the iPhone (landscape) should fall between <code>(min-width:30em) and (max-width:59.9999em)</code> and the iPad (landscape) should fall between <code>(min-width:60em) and (max-width:89.9999em)</code>.  Unfortunately, they both fall one query narrower.</p>
  
  <p>While searching through stackoverflow, I found <a href="https://stackoverflow.com/questions/2545542/font-size-render-in-iphone/3839465#3839465">this post</a> that says the default font size in mobile Safari is 12px (not 16px, as normal).  I had not seen that on any other sites, but the calculations seemed to make sense (further calculating doesn't seem to put them in different media query groups, though).</p>
  
  <p>In response, to that post, I set a base font-size of 16px.</p>
  
  <p>CSS:</p>
  
  <pre><code>html { font-size:16px; }
  </code></pre>
  
  <p>My thought was that it would over-ride the browser's default setting and match with every other browser that was being tested.  Unfortunately, mobile Safari is still using the portrait layout when in landscape.</p>
  
  <p>I had read a few pages that mentioned needing to refresh with Safari (not sure if it was mobile or desktop), so I even tried that.</p>
  
  <p>Does anyone have a reason why this is happening?  As mentioned, I've created other sites using px-based media queries and they function as expected.</p>