简体   繁体   English

Windows Phone 8:无法识别CSS方向

[英]Windows Phone 8: CSS orientation not recognized

I am attempting to pick up orientation on all mobile devices in css and trigger some css on the orientation change. 我试图在css中的所有移动设备上获取方向并触发方向更改的一些css。

This is a simple test of the code: 这是对代码的简单测试:

    <div class="orientation">
        <span class="landscape">Landscape</span>
        <span class="portrait">Portrait</span>
    </div>

and the CSS is: 而CSS是:

     .portrait, .landscape {
         position: absolute;
         top: 0px;
         left: 0px;
     }

    .portrait {display: block;}
    .landscape {display: none;}

    @media screen and (orientation:landscape) {
        .portrait {display: none;}
        .landscape {display: block;}
    }

Now in all webkit browsers (android, ios) and even desktop it works fine (bar a couple of devices) but in the new windows phone 8 devices it doesn't pick up the change. 现在在所有的webkit浏览器(android,ios)甚至桌面上都可以正常使用(禁止使用几个设备),但在新的Windows手机中,8个设备并没有获得更改。 (Nokia lumia 920) (诺基亚lumia 920)

I've also had a look at some javascript resources (I am no javascript wiz though) namely: 我也看了一些javascript资源(我不是javascript wiz),即:

But from what i can tell, that still doesn't work for windows phone 8 devices? 但据我所知,这仍然不适用于Windows Phone 8设备?

Is there a specific MS css code I need to use or is there another way to do it? 我需要使用特定的MS css代码还是有其他方法可以实现? it would be great if there was a cross browser / cross mobile device capable piece of javascript that can pick up the change and just add a class to the body tag on the change. 如果有一个跨浏览器/跨移动设备的javascript可以接收更改并且只是在更改的body标签上添加一个类,那将会很棒。

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

@media all and (orientation:landscape) is definitely the right direction you should take. @media all and (orientation:landscape)绝对是你应该采取的正确方向。 There's a live demo of that in the build2012 talk on WP8 and HTML. WP8和HTML的build2012讲座中有一个现场演示。 See time stamp 35:30~ for orientation changes on WP8 IE10 @ http://channel9.msdn.com/Events/Build/2012/2-015 请参阅时间戳35:30~以获取WP8 IE10上的方向更改@ http://channel9.msdn.com/Events/Build/2012/2-015

According to this blog entry , when you view a web page locally, IE defaults into backwards compatible mode for intranet sites. 根据此博客条目 ,当您在本地查看网页时,IE默认为内部网站点的向后兼容模式。 This is probably what's causing it not to work as intended. 这可能是因为它无法按预期工作。 You can fix it by adding the following meta tag: 您可以通过添加以下元标记来修复它:

<meta http-equiv="x-ua-compatible" content="IE=edge" />

Although this is a bit of an old question, I had this same issue with orientation not being recognized by IE11 on a Surface Pro 2 tablet. 虽然这是一个古老的问题,但我有同样的问题,在Surface Pro 2平板电脑上IE11无法识别方向。 It came down to whitespace. 它归结为空白。 I thought I'd share the solution in case someone else has the same issue. 我以为我会分享解决方案以防其他人遇到同样的问题。

Doesn't work: 不起作用:
@media all and (orientation : portrait) {

Works: 作品:
@media all and (orientation:portrait) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM