iPhone 5有一个更长的屏幕,它不捕捉我的网站的移动视图。什么是新的响应式设计查询的iPhone 5,我可以结合现有的iPhone查询?iPhone 5的CSS媒体查询
我现在的媒体查询是这样的:
@media only screen and (max-device-width: 480px) {}
iPhone 5有一个更长的屏幕,它不捕捉我的网站的移动视图。什么是新的响应式设计查询的iPhone 5,我可以结合现有的iPhone查询?iPhone 5的CSS媒体查询
我现在的媒体查询是这样的:
@media only screen and (max-device-width: 480px) {}
另一个有用的媒体功能是device-aspect-ratio
。
请注意,iPhone 5没有16:9长宽比。实际上是40:71。
iPhone < 5:
@media screen and (device-aspect-ratio: 2/3) {}
iPhone 5:
@media screen and (device-aspect-ratio: 40/71) {}
iPhone 6:
@media screen and (device-aspect-ratio: 375/667) {}
iPhone 6加:
@media screen and (device-aspect-ratio: 16/9) {}
的iPad:
@media screen and (device-aspect-ratio: 3/4) {}
参考:
Media Queries @ W3C
iPhone Model Comparison
Aspect Ratio Calculator
我喜欢这种方法,但无法在PhoneGap应用程序webview中工作,直到像Stephen Sprawl所解释的那样添加-webkit-min-device-pixel-ratio http://zsprawl.com/iOS/2012/09/css-媒体查询,这换了,iphone-5。(device-aspect-ratio:40/71)和(-webkit-min-device-pixel-ratio:2){iphone5 for phonehaps } – TaeKwonJoe
我必须添加'和( -webkit-min-device-pixel-ratio:2)'在iPhone 5媒体查询中使其在PhoneGap webview中工作,如@TaeKwonJoe所述 –
感谢您对此进行更新以包含iPhone 6! – Maverick
有了这个,我信用this blog:
@media only screen and (min-device-width: 560px) and (max-device-width: 1136px) and (-webkit-min-device-pixel-ratio: 2) {
/* iPhone 5 only */
}
记住它反应了iPhone 5,而不是特定的iOS版本安装在所述设备上。
要使用现有版本进行合并,你应该能够逗号分隔它们:
@media only screen and (max-device-width: 480px), only screen and (min-device-width: 560px) and (max-device-width: 1136px) and (-webkit-min-device-pixel-ratio: 2) {
/* iPhone only */
}
注:我没有测试上面的代码,但我测试过用逗号分隔@media
查询之前,他们工作得很好。
请注意,上述可能会遇到一些其他共享相似比率的设备,如Galaxy Nexus。这是一个额外的方法,将只针对具有640px(560px由于一些奇怪的显示像素异常)和960px(iPhone < 5)和1136px(iPhone 5)之一的尺寸的设备。
@media
only screen and (max-device-width: 1136px) and (min-device-width: 960px) and (max-device-height: 640px) and (min-device-height: 560px),
only screen and (max-device-height: 1136px) and (min-device-height: 960px) and (max-device-width: 640px) and (min-device-width: 560px) {
/* iPhone only */
}
你应该把“-webkit-min-device-pixel-ratio”设置为1.5来捕捉所有的iPhone?
@media only screen and (max-device-width: 480px), only screen and (min-device-width: 640px) and (max-device-width: 1136px) and (-webkit-min-device-pixel-ratio: 1.5) {
/* iPhone only */
}
哪个iPhone使用的设备像素比率为1.5? – BoltClock
我强烈建议根据设备宽度进行媒体查询,而不是设备名称(iPhone)。所以如果iPhone 5的宽度更大,只需要使用它即可。 –
你可以得到你的答案很容易对iPhone5的与移动设备的媒体特征数据库的其他智能手机一起:
http://pieroxy.net/blog/2012/10/18/media_features_of_the_most_common_devices.html
您甚至可以在同一网站上的测试页上获取您自己的设备值。
(免责声明:这是我的网站)
无响应的工作对我来说靶向phonegapp应用。
如下面的link分,下面的解决方案工作。
@media screen and (device-height: 568px) and (orientation: portrait) and (-webkit-min-device-pixel-ratio: 2) {
// css here
}
对我来说,是做了工作的查询是:
only screen and (device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)
所有这些问题的答案上面列出,使用max-device-width
或max-device-height
媒体查询,遭受很强的错误:他们也瞄准很多其他受欢迎的移动设备(可能是不需要的,从未测试过,或将在未来上市)。
此查询将适用于任何具有较小屏幕的设备,并且可能会损坏您的设计。
结合类似的设备特定媒体查询(HTC,三星,iPod,Nexus ...),这种做法将启动定时炸弹。对于debigging,这个想法可以让你的CSS成为一个不受控制的spagetti。你永远不能测试所有可能的设备。
请注意,只有媒体查询始终瞄准的iPhone5并没有别的是:
/* iPhone 5 Retina regardless of IOS version */
@media (device-height : 568px)
and (device-width : 320px)
and (-webkit-min-device-pixel-ratio: 2)
/* and (orientation : todo: you can add orientation or delete this comment)*/ {
/*IPhone 5 only CSS here*/
}
注意确切的宽度和高度,而不是最大宽度在这里检查。
现在有什么解决方案?如果你想要写一个网页,将寻找所有可能的设备好,最好的做法是使用降解
/*退化模式 我们正在检查屏幕宽度只有 肯定的是,这将改变从纵向转向景观*/
/*css for desktops here*/
@media (max-device-width: 1024px) {
/*IPad portrait AND netbooks, AND anything with smaller screen*/
/*make the design flexible if possible */
/*Structure your code thinking about all devices that go below*/
}
@media (max-device-width: 640px) {
/*Iphone portrait and smaller*/
}
@media (max-device-width: 540px) {
/*Smaller and smaller...*/
}
@media (max-device-width: 320px) {
/*IPhone portrait and smaller. You can probably stop on 320px*/
}
如果您的网站访问者的30%以上来自手机,把这个方案颠倒,提供移动优先的方法。在这种情况下使用min-device-width
。这将加快移动浏览器的网页渲染速度。
我会先进行增强和移动。这是从移动和开始使用最小设备宽度。 – primavera133
另请注意,仅匹配iPhone 5的高度/宽度/像素比例解决方案也会匹配出现的具有相同特征的下一个手机。您的答案的整体主题是正确的:根据*特定设备思考*是错误的方式。 – Pointy
对于清晰明确的评论+1 +1 – Philip007
AFAIK没有iPhone使用1.5
iPhone 3G/3GS的像素比:(-webkit装置像素比:1) iPhone 4G/4GS/5G:(-webkit设备像素2)
只是一个非常快速的补充,因为我一直在测试一些选项,并一路错过了这个。确保你的页面有:
<meta name="viewport" content="initial-scale=1.0">
/* iPad */
@media screen and (min-device-width: 768px) {
/* ipad-portrait */
@media screen and (max-width: 896px) {
.logo{
display: none !important;
}
}
/* ipad-landscape */
@media screen and (min-width: 897px) {
}
}
/* iPhone */
@media screen and (max-device-width: 480px) {
/* iphone-portrait */
@media screen and (max-width: 400px) {
}
/* iphone-landscape */
@media screen and (min-width: 401px) {
}
}
iPhone 5在纵向&景观
@media only screen
and (min-device-width : 320px)
and (max-device-width : 568px) {
/* styles*/
}
iPhone 5在景观
@media only screen
and (min-device-width : 320px)
and (max-device-width : 568px)
and (orientation : landscape) {
/* styles*/
}
iPhone 5在纵向
@media only screen
and (min-device-width : 320px)
and (max-device-width : 568px)
and (orientation : portrait) {
/* styles*/
}
我们可以看到您现有的媒体查询吗? – BoltClock
试试这个吗? http://halgatewood.com/iphone-5-media-query/ – sachleen