问题描述:https://github.com/jquery/jquery-mobile/issues/2581

本文转自:http://www.456bereastreet.com/archive/201212/ios_webkit_browsers_and_auto-zooming_form_controls/

One thing about iOS browsers that can be pretty frustrating, both as a developer and as a user, is when you open a site on an iPhone or iPod Touch (not iPad) and want to enter some text in a text field or pick an option from a select menu. Very often the browser will automatically zoom in on the entire page a little when you tap the form control.

The intention is likely to be helpful and ensure that you can see the text you’re typing or the options in the select element. This is fine, of course. What’s annoying is that the browser doesn’t zoom back out once you’re done with the control, so you have to pinch the screen and manually zoom out. Not showstopping, but rather annoying. This behaviour seems to be the same for all browsers that use WebKit, which as far as I know means all iOS browsers except Opera Mini (which does not auto-zoom form controls).

For end users I don’t know if it is possible to avoid this, but for web developers there are a couple of ways.

One, which I do not recommend, is to remove the user’s ability to zoom in on the page. That reduces usability and accessibility in a way that’s far more annoying than having to zoom back out after interacting with form controls. Please don’t do that.

The other way is to make sure form controls have large enough text that the browser doesn’t feel it needs to zoom in on them. The magic size seems to be a calculated font-size of 16px. If that seems a bit large, consider that it’s often a good idea to increase text size a little for small screens to make reading easier. I know that sounds a bit counter-intuitive, but try it.

If you don’t want to make all text 16px or larger, maybe you can at least do so fortextareaselect, and the relevant states of input elements. If that isn’t an option either, you can do it on focus:

input[type="text"]:focus,
textarea:focus,
select:focus {
font-size:16px;
}

If you use other text-based input types than text, add selectors as needed.

For clarity I’ve used px as the font-size unit here, so if you use ems or rems or something else, enter whatever is equivalent to 16px instead.

As for how to target the browsers that are affected, I think using a media query to match a suitable device width is good enough, at least for now. As far as I know only iOS browsers auto-zoom form controls, and only on iPhones and iPods. That currently makes the iPhone 5’s 568px in landscape orientation the largest device width to target, so this should work:

@media only screen and (max-device-width:568px) {
input[type="text"]:focus,
textarea:focus,
select:focus {
font-size:16px;
}
}

You’ll hit non-WebKit, non-iOS browsers as well, but that’s likely not a big deal. YMMV, but I’d rather do that than start browser sniffing.

最新文章

  1. apache开启rewrite重写
  2. uniq
  3. css圆角矩形及去掉空格属性
  4. OpenGL2-绘制三角形
  5. OR查询
  6. MarkDown入门指南
  7. Python的字典和JSON
  8. [Luogu 1559]运动员最佳匹配问题
  9. day43 mysql 基本管理,[破解密码以及用户权限设置]以及慢日志查询配置
  10. RNN(3) ------ “blog:RNN学习之路”
  11. json--处理框架
  12. c#devexpress GridContorl datasource为 类字段的实现方式 非datatable方式以及其他操作总结
  13. 实战Apache+Tomcat集群和负载均衡
  14. ajax的一些小知识
  15. fiddler抓web请求
  16. Node中使用mysql模块遇到的问题
  17. Oracle客户端与Toad、plsql developer安装
  18. linux下从源代码安装git的问题(install from source)
  19. linux上的常用命令
  20. preloadjs实现网页资源预加载

热门文章

  1. poj - 3041 Asteroids (二分图最大匹配+匈牙利算法)
  2. Redis2019年3.22
  3. 关于python内存管理里的引用计数算法和标记-清楚算法的讨论
  4. Centos系统备份
  5. STL之关联容器的映射底层
  6. 查找olr备份路径
  7. 86. LotusScript中的数组函数
  8. HDMI接口基础知识及硬件设计
  9. Android自己定义无下划线ClickableSapn超链接文本样式
  10. react 中的 setState