Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobile Safari Reflow without Resize - buggy behavior

Edit 2 This question is looking for a smooth, clean way to reflow text on the iPhone.

Improving a web app to have 2 different widths (320 & 480) depending on the orientation. The intent is also to have 480 wide available for non mobile (ie > 480 width) screens. It is working mostly as desired, except for when the page is refreshed in landscape. This causes the layout to go back to 320 (on the left side) and leave a dark bar on the right.

  • Load in Portrait

1. Portrait (after load)

  • Rotate to Landscape

2. Landscape (after rotate)

  • Refresh in Landscape

3. Landscape (after refresh)

It takes rotating to portrait and back to get resize and image 2 again. That is a usability issue for me. The page resizes & rotates great on Android and is 'full-size' on desktop.

Anyone know what I'm missing? I've attempted many iterations of this and read about a couple bug solutions. None of the ideas are changing the outcome. About to file a bugreport. I have a hunch it is in the lines of the media query #container.

Edit: The site was built for mobile (320 wide). The desire is to expand the usage of space when that space is available. The main intent is to have text & elements reflow. Looking at the photos, notice the alignment of the input fields with their labels.

I have tried 2 approaches to make this work. Other was to use javascript to change #container width. Currently using with the following media queries at the end of inline style sheet. I prefer to solve this with media query.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1, initial-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>The Title</title>
    <style type="text/css">
        html {
            margin: 0;
            padding: 0;
        }
        body {
            font: 14px Verdana, Geneva, Arial, Helvetica, sans-serif;
        }
        #container {
            margin: auto;
            width: 480px;
         .....
        @media screen and (max-width: 480px) {
            body {
                -webkit-text-size-adjust: none;
            }
            #container {
                 max-width: 480px !important;
                 width: 100% !important;
            }       
        }
        @media screen and (max-width: 320px) {
            body {
                -webkit-text-size-adjust: none;
            }
            #container {
                 max-width: 320px !important;
                 width: 100% !important;
            }       
        }
    </style>
      .....
like image 500
David Avatar asked Jun 11 '12 01:06

David


1 Answers

Got a breakthrough. After dozens of variations in the media queries, this code has 'broken' the problem:

function orientation_change() {
    if (window.orientation == 0 || window.orientation == 180)
        document.getElementById("viewport").setAttribute("content", "width=device-width, maximum-scale=1.0, initial-scale=1.0, user-scalable=no");
    else if (window.orientation == -90 || window.orientation == 90)
        document.getElementById("viewport").setAttribute("content", "width=device-height, maximum-scale=1.0, initial-scale=1.0, user-scalable=no");     
}

with:

<body onload="orientation_change();" onorientationchange="orientation_change();">

The media queries of the original question are still included to reflow the text when a rotation occurs. However the refresh partial black screen issue is gone. Found insight on Apple iOS Safari Web Content Guide. In particular, Handling Orientation Events.

I hope this helps in the process of Responsive Web Design.

like image 125
David Avatar answered Oct 22 '22 08:10

David