问题描述: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.

[转]iOS WebKit browsers and auto-zooming form controls的更多相关文章

  1. iOS Programming Introduction to Auto Layout 自动布局

    iOS Programming Introduction to Auto Layout   自动布局 A single application that runs natively on both t ...

  2. C#中缓存的使用 ajax请求基于restFul的WebApi(post、get、delete、put) 让 .NET 更方便的导入导出 Excel .net core api +swagger(一个简单的入门demo 使用codefirst+mysql) C# 位运算详解 c# 交错数组 c# 数组协变 C# 添加Excel表单控件(Form Controls) C#串口通信程序

    C#中缓存的使用   缓存的概念及优缺点在这里就不多做介绍,主要介绍一下使用的方法. 1.在ASP.NET中页面缓存的使用方法简单,只需要在aspx页的顶部加上一句声明即可:  <%@ Outp ...

  3. objective-c ios webkit 本地存储local-storage

    我有一个Cocoa / Objective-C的应用程序,它嵌入了一个WebKit的web视图.我需要打开的数据库支持和本地存储.我知道这是可以做到-我有它在Safari中工作-但我无法找到如何设置这 ...

  4. iOS 开发实践之 Auto Layout

    原:http://xuexuefeng.com/autolayout/?utm_source=tuicool 本文是博主 iOS 开发实践系列中的一篇,主要讲述 iOS 中 Auto Layout(自 ...

  5. iOS,自动布局autoresizing和auto layout,VFL语言

    1.使用autoresizing 2.使用autolayout 3.VFL语言(Visual Format Language:可视化格式语言) 使用autoresizing 点击xib文件,去掉使用a ...

  6. 解决 iOS webkit 使用CSS动画时闪烁的问题

    -webkit-backface-visibility: hidden;

  7. Angular5 错误: ngModel cannot be used to register form controls with a parent formGroup directive

    在创建一个表单时,出现了这样的错误: 原因是,在最外层的form中使用了 formGroup 指令,但在下面的某个input 元素中,使用了ngModel 指令,但没有加入formControl 指令 ...

  8. C# 添加Excel表单控件(Form Controls)

    在Excel中,添加的控件可以和单元格关联,我们可以操作控件来修改单元格的内容,在下面的文章中,将介绍在Excel中添加几种不同的表单控件的方法,包括: 添加文本框(Textbox) 单选按钮(Rad ...

  9. iOS发展 ---- 至iPhone 6自适应布局设计 Auto Layout

    Apple从iOS 6增加了Auto Layout后開始就比較委婉的開始鼓舞.建议开发人员使用自适应布局,可是到眼下为止,我感觉大多数开发人员一直在回避这个问题,无论是不是因为历史原因造成的,至少他们 ...

随机推荐

  1. POJ2632 Crashing Robots 解题报告

    Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...

  2. python 交互模式 方向键乱码问题解决

    python交互模式下通常用向上键来找到之前执行的命令,用左右键移动光标.这很方便.但有的时候这些键在按完后却会出现乱码. 本文只解决CentOS 6.4 下 python2.7.8 的乱码问题. 这 ...

  3. HDU 1030 数学题

    给出两点,求这两点在图上的最短路径 分别以最上,左下,右下为顶点,看这个三角图形 ans=这三种情况下两点的层数差 #include "stdio.h" #include &quo ...

  4. cocos2dx-3.0(21) 移植android平台 说多了都是泪

    ----我的生活,我的点点滴滴! ! 网上3.0的教程真心少.能够说没有吧,大多都是2.x 或者 3.0測试版之类的,因为我心大,没有照着2.x去搞,后来搞完后总结了一下,发觉事实上3.0的移植and ...

  5. Highcharts构建加权平均值图表

    Highcharts构建加权平均值图表 加权平均值图表是将图表中多个数据列值.依据加权算法计算获取平均值,并加入生成一个加权折线.在这里,我们直接使用第三方插件Dynamic Weighted Ave ...

  6. 混合式框架-AgileLite

    Agile Lite是一个HTML5移动前端框架.支持jQuery和Zepto双引擎.而且提供与UI无关的独立框架,内置了Flat UI样式和Ratchet样式.同一时候也支持单页模式和多页模式开发. ...

  7. scikit-learn:3. Model selection and evaluation

    參考:http://scikit-learn.org/stable/model_selection.html 有待翻译,敬请期待: 3.1. Cross-validation: evaluating ...

  8. Android之——jni通用工具方法

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47002207 1.将java字符串转化为c++字符串 /** *工具方法 *将ja ...

  9. pat(A) 1063. Set Similarity(STL)

    代码: #include<cstdio> #include<cstring> #include<set> using namespace std; set<i ...

  10. cocos2dx 在android平台打开文件问题

        我们有一个项目是基于cocos2dx + lua,在网络部分用到了protobuf, 在初始化protobuf的时候须要读取本地文件,用lua的io.open读取文件在windows,ios上 ...