Note that there are some explanatory texts on larger screens.

plurals
  1. POCSS Media Query - Soft-keyboard breaks css orientation rules - alternative solution?
    primarykey
    data
    text
    <p>I am working with multiple tablet devices - both Android <del>and iOS</del>. Currently I have following resolution variations for all the tablets.</p> <ul> <li>1280 x 800</li> <li>1280 x 768</li> <li><del>1024 x 768 (iPad Obviously)</del> - iPad does not have this issue</li> </ul> <p>Simplest way to apply device orientation based style is to use media query's orientation using following syntax.</p> <pre><code>@media all and (orientation:portrait) { /* My portrait based CSS here */ } @media all and (orientation:landscape) { /* My landscape based CSS here */ } </code></pre> <p>This works perfectly fine on all tablet devices. <strong>BUT</strong>, the problem is, when device is in portrait mode and user taps on any input field (eg. search) the soft-keyboard pops up - which reduces the visible area of web page and forces it to render in landscape based css. On android tablet devices, it depends on keyboard's height. So, ultimately the web page looks broken. Therefore, I can't use CSS3's orientation media query to apply styles based on orientation (unless there is better media query to target orientation). Here is a fiddle <a href="http://jsfiddle.net/hossain/S5nYP/5/" rel="noreferrer">http://jsfiddle.net/hossain/S5nYP/5/</a> which emulates this - for device testing use full test page - <a href="http://jsfiddle.net/S5nYP/embedded/result/" rel="noreferrer">http://jsfiddle.net/S5nYP/embedded/result/</a></p> <p>Here is a screenshot of the behaviour taken from the demo page. <img src="https://i.stack.imgur.com/tNMlf.png" alt="enter image description here"></p> <p>So, is there any alternative to takle this issue, I'm open to JavaScript based solution if native CSS based solution does not work.</p> <p>I found a snippet on <a href="http://davidbcalhoun.com/2010/dealing-with-device-orientation" rel="noreferrer">http://davidbcalhoun.com/2010/dealing-with-device-orientation</a> which suggests to add class on and target based on that. For example:</p> <pre><code>&lt;html class="landscape"&gt; &lt;body&gt; &lt;h1 class="landscape-only"&gt;Element Heading - Landscape&lt;/h1&gt; &lt;h1 class="portrait-only"&gt;Element Heading - Portrait&lt;/h1&gt; &lt;!-- .... more... -&gt; # CSS .landscape .landscape-only { display:block; } .landspace .portrait-only { display:none; } .portrait .portrait-only { display:block; } .portrait .landscape-only { display:none; } </code></pre> <p>What do you guys think about this? Do you have better solution? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload