【问题标题】:How to force a mobile web page to load in landscape如何强制移动网页横向加载
【发布时间】:2017-02-28 17:23:33
【问题描述】:

我们网站上有一个移动网页,加载时需要在浏览器中始终以横向呈现。另外,页面需要横向锁定,这样设备就不能改变方向了。

主要移动浏览器或 CSS 属性中是否有任何 JS API 可以完成此操作?

【问题讨论】:

标签: javascript css mobile viewport


【解决方案1】:

您可以尝试使用此代码:

#container { display:block; }

@media only screen and (orientation:portrait){

  #container {

   height: 100vw;

   -webkit-transform: rotate(90deg);

   -moz-transform: rotate(90deg);

   -o-transform: rotate(90deg);

   -ms-transform: rotate(90deg);

   transform: rotate(90deg);

  }

}

@media only screen and (orientation:landscape){

  #container {

  -webkit-transform: rotate(0deg);

  -moz-transform: rotate(0deg);

  -o-transform: rotate(0deg);

  -ms-transform: rotate(0deg);

  transform: rotate(0deg);

   }

您还应该将其添加到正文标签中:

 <BODY id="container">

我找到了这个解决方案here。同一个博客也提供了额外的建议,但我没有尝试过,因为上面的效果很好

【讨论】:

    猜你喜欢
    • 2012-06-14
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 2012-03-11
    相关资源
    最近更新 更多