简体   繁体   English

iPhone上的CSS媒体查询

[英]CSS media query on iPhone

I'm trying to use a CSS media query, specifically targeting the iPhone.我正在尝试使用 CSS 媒体查询,专门针对 iPhone。

It works when I use a regular link rel:当我使用常规链接 rel 时,它可以工作:

<link rel="stylesheet" type="text/css" href="css/mobile.css" />

However, when I try this media query it doesn't work:但是,当我尝试此媒体查询时,它不起作用:

<link rel="stylesheet" type="text/css" href="css/mobile.css" 
      media="only screen and (max-width: 640px)" /> 

How can I use a CSS media query to target the iPhone?如何使用 CSS 媒体查询来定位 iPhone?

Try:尝试:

<link rel="stylesheet" type="text/css" href="css/mobile.css" media="only screen and (max-device-width: 480px)" />

The difference is max-device-width instead of just max-width .区别在于max-device-width而不仅仅是max-width Also see 2) on http://blogs.sitepoint.com/iphone-development-12-tips/ .另请参阅http://blogs.sitepoint.com/iphone-development-12-tips/上的 2)。

I know this isnt exacly what you asked but i have just answered something similar and may help:我知道这不是你问的,但我刚刚回答了类似的问题,可能会有所帮助:

<meta name='viewport' content='width=device-width; initial-scale=1.0;' />

There are plenty of parameters for CONTENT, some of them are: CONTENT 有很多参数,其中一些是:

maximum-scale=3.0; //Maximum zoom allowed 0 to 10.0. default is 1.6
minimum-scale=0.5; //Minimum zoom allowed 0 to 10.0. default is 0.25
user-scalable=1; //YES/NO
width=device-width; //default if not set is 980px 
initial-scale=1.0; //Initial zoom. 0 to 10.0. 1.0 would be 100%
height=device-height;  

Content in UIWebView on iOS 3.1.3 appears zoomed on but on iOS 4.3 appears fine iOS 3.1.3 上 UIWebView 中的内容显示为放大,但在 iOS 4.3 上显示正常

Edit: You can use these params in Safari too, forget the uiwebview thing thats just for native applications.编辑:您也可以在 Safari 中使用这些参数,忘记仅适用于本机应用程序的 uiwebview 东西。

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

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