简体   繁体   English

PhoneGap + Android +媒体查询

[英]PhoneGap + Android + media queries

I have been struggling with this for a week now. 我一直在努力这一周。 I have read tons of posts/webs/tips&tricks, but I just can't figure this out. 我已经阅读了大量的帖子/网站/提示和技巧,但我无法弄清楚这一点。

I need to set CSS rules for different screen sizes and orientations. 我需要为不同的屏幕尺寸和方向设置CSS规则。 But the recognition it's not working. 但认识到它不起作用。

I have tryed with: min-width, max-width, min-height, max-height, min-device-width, max-device-width, min-device-height, max-device-height, orientation: portrait, orientation: landscape, media="only screen and (max...", media="screen and (max...", media="(max.."), all kind of convinations, none of this works for all the resolutions and orientations. 我尝试过:min-width,max-width,min-height,max-height,min-device-width,max-device-width,min-device-height,max-device-height,orientation:portrait,orientation :landscape,media =“only screen and(max ...”,media =“screen and(max ...”,media =“(max ..”),所有类型的信念,这些都不适用于所有决议和方向。

This is and example: 这是一个例子:

<link rel="stylesheet" href="css/iscroll.css" />
<link rel="stylesheet" href="css/iscroll_600.css"  type="text/css" media="only screen and (max-width: 600px) and (max-height: 1024px) and (orientation: portrait)"/>    
<link rel="stylesheet" href="css/iscroll_600.css"  type="text/css" media="only screen and (max-width: 1024px) and (max-height: 600px) and (orientation: landscape)"/> 
<link rel="stylesheet" href="css/iscroll_1280.css" type="text/css" media="only screen and (max-width: 800px) and (max-height: 1280px) and (orientation: portrait)"/>
<link rel="stylesheet" href="css/iscroll_1280.css" type="text/css" media="only screen and (max-width: 1280px) and (max-height: 800px) and (orientation: landscape)"/>

How can I address this problem? 我该如何解决这个问题? Thanks 谢谢

dhcmega dhcmega

It looks like it works this way 它看起来像这样工作

<link rel="stylesheet" href="css/style_default.css" />
<link rel="stylesheet" href="css/style320.css" media="(min-width: 241px) and (max-width: 320px) and (orientation: portrait)"/>
<link rel="stylesheet" href="css/style480.css" media="(min-width: 321px) and (max-width: 480px) and (orientation: portrait)"/>  
<link rel="stylesheet" href="css/style540.css" media="(min-width: 481px) and (max-width: 540px) and (orientation: portrait)"/>
<link rel="stylesheet" href="css/style600.css" media="(min-width: 541px) and (max-width: 600px) and (orientation: portrait)"/>  
<link rel="stylesheet" href="css/style1280.css" media="(min-width: 601px) and (max-width: 800px) and (orientation: portrait)"/>
<link rel="stylesheet" href="css/style1536.css" media="(min-width: 801px) and (max-width: 1152px) and (orientation: portrait)"/>
<link rel="stylesheet" href="css/style320.css" media="(min-width: 321px) and (max-width: 480px) and (orientation: landscape)"/>
<link rel="stylesheet" href="css/style480.css" media="(min-width: 481px) and (max-width: 800px) and (orientation: landscape)"/>  
<link rel="stylesheet" href="css/style540.css" media="(min-width: 801px) and (max-width: 960px) and (orientation: landscape)"/>    
<link rel="stylesheet" href="css/style600.css" media="(min-width: 961px) and (max-width: 1024px) and (orientation: landscape)"/> 
<link rel="stylesheet" href="css/style1280.css" media="(min-width: 1025px) and (max-width: 1280px) and (orientation: landscape)"/>    
<link rel="stylesheet" href="css/style1536.css" media="(min-width: 1281px) and (max-width: 1536px) and (orientation: landscape)"/>

It is like creating different sets of resolutions that does NOT overlap at all 这就像创建不重叠的不同分辨率组

Have you tried it using javascript to see what is being returned by the media query, to check the results? 您是否尝试过使用javascript来查看媒体查询返回的内容,以检查结果?

var mq = window.matchMedia( "only screen and (max-width: 600px) and (max-height: 1024px) and (orientation: portrait)" );  

if (mq.matches) {
    // window width is exactly 600x1024 and portrait
}
else {
    // window width is exactly 600x1024 and portrait
}

Link for reference . 链接供参考

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

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