0

I've put the following meta tag in my mobile HTML

 <meta name = "viewport" content = "initial-scale = 1.0">

After I coded the css file for mobile version, I realized it doesn't look good on lanscape mode since it has a different width size. I get an empty 160 pixel area on the right side.

Other than writing a separate css file for landscape mode, is there any way getting out of this?

TheAlbear
  • 5,507
  • 8
  • 51
  • 84
archvile
  • 169
  • 4
  • 8

4 Answers4

2

You also need to bind the orientation change event. You can do it with this sample script:

<script>
$(function(){

  function orient() {  
    if (window.orientation == 0 || window.orientation == 180) {
      $('.featured').css('display','none');
    orientation = 'portrait';
        return false;
    }
    else if (window.orientation == 90 || window.orientation == -90) {
      $('.featured').css('display','block');
        orientation = 'landscape';
        return false;
    }
  }

  $(window).bind( 'orientationchange', function(e){
    orient();
  });

})();

</script>
marcinsdance
  • 634
  • 7
  • 17
1

If your css layout is based on screen percents instead of absolute values it should allow you to adjust to any screen layout without multiple css files just fine.

Look at the percent option: http://www.w3schools.com/cssref/pr_dim_width.asp

Or if you had a layout you wanted constant, you could center it.

Nathan Tornquist
  • 6,468
  • 10
  • 47
  • 72
0

center align the outise wrapper.

body{
    max-width:786;/*target size of page*/
    margin:0 auto auto auto;
}

is the easiest way.

Dpolehonski
  • 948
  • 6
  • 11
  • additional comment: just because it may be the easiest doesn't mean it'll be the best. – Dpolehonski Jul 12 '12 at 16:29
  • Mobile devices vary so much in dimensions that the best bet is a % based layout for the width. Takes a bit of getting your head round but it's so much better. – SpaceBeers Jul 12 '12 at 16:35
0

You can use media queries to detect orientation changes and run different styles for each all in the same stylesheet.

Also for mobile it's a good idea to you use % rather than px for widths - what units do you use for css for mobile web apps?

/* Portrait */
@media screen and (orientation:portrait) {
    /* Portrait styles */
}
/* Landscape */
@media screen and (orientation:landscape) {
    /* Landscape styles */
}
Community
  • 1
  • 1
SpaceBeers
  • 13,617
  • 6
  • 47
  • 61