mobile webapp CSS breaks on orientation change

梦想的初衷 提交于 2019-12-08 05:22:29

Use CSS Media Queries to update your design

iPhone doesn’t support orientation currently (Thx @vava), so use media queries for width below

Orientation queries:

http://www.w3.org/TR/css3-mediaqueries/#orientation

@media all and (orientation:portrait) {
  h1 {
    color: red;
  }
}
@media all and (orientation:landscape) {
  h1 {
    color: blue;
  }
}

Width queries:

/* Portrait */
@media only screen and (max-width: 320px) {
  h1 {
    color: red;
  }
}
/* Landscape */
@media only screen and (min-width: 321px) {
  h1 {
    color: blue;
  }
}

Check out http://lessframework.com for examples of width-based media query design.

There are many other media query options to target specific attributes of the viewing sesssion:
http://www.w3.org/TR/css3-mediaqueries/#contents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!