PhoneGap css媒体查询方面不起作用

时间:2013-03-22 10:00:42

标签: css cordova media-queries iphone-5

我开发了一款以iPhone作为设计目标的应用程序(即640x960 => 2:3),我已经使用布局中每个分区的百分比来完成,因此ui在设备大小方面有所不同。现在这适用于iPad,但我遇到了9:16宽高比设备的问题。我已经使用了媒体查询,但是没有用。

除法的默认代码是:

.top_bar {
    height: 9%;
}

现在使用媒体查询宽高比:

@media screen and (min-device-aspect-ratio: 9/16) {
    .top_bar {
        height: 7.5%;
    }
}

但这不起作用,不是在浏览器上而是在设备上。

我已将viewport metatag内容值添加为

content="user-scalable=no, width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, target-densityDpi=device-dpi"

后来我尝试了多种分辨率来检测宽高比:

@media 
only screen and (min-device-width: 320px) and (min-device-height: 560px),
only screen and (min-device-width: 480px) and (min-device-height: 850px),
only screen and (min-device-width: 640px) and (min-device-height: 1130px),
only screen and (min-device-width: 720px) and (min-device-height: 1270px),
only screen and (min-device-width: 768px) and (min-device-height: 1360px),
only screen and (min-device-width: 800px) and (min-device-height: 1422px),
only screen and (min-device-width: 960px) and (min-device-height: 1700px),
only screen and (min-device-width: 1080px) and (min-device-height: 1910px)
{

.top_bar {
    height: 7.5%;
}
}

但这也不起作用。

更新 - 修正

尝试一点,只是将 min-device-aspect-ratio:9/16 更改为 max-aspect-ratio:9/16 现在工作正常。

@media screen and (max-aspect-ratio: 9/16) {
    .top_bar {
        height: 7.5%;
    }
}

1 个答案:

答案 0 :(得分:1)

将您的元标记设为这样 <meta name="viewport" content="width=device-width, initial-scale=1">

编写您的媒体查询

@media only screen and (min-width: 768px) and (max-width: 956px){
.top_bar { height: 7.5%;}
}