博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[转]iOS WebKit browsers and auto-zooming form controls
阅读量:5936 次
发布时间:2019-06-19

本文共 2759 字,大约阅读时间需要 9 分钟。

问题描述:

 

本文转自:

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 fortextarea, select, 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.

 

转载地址:http://nyvtx.baihongyu.com/

你可能感兴趣的文章
RabbitMQ广播:fanout模式
查看>>
部署Java项目到阿里云服务器(Ubuntu16.04 64位)
查看>>
货币转换常用方法
查看>>
Manthan, Codefest 17
查看>>
TOJ4505: KOSARE
查看>>
csa Round #73 (Div. 2 only)
查看>>
Extjs4.2如何实现鼠标点击统计图时弹出窗口来展示统计的具体列表信息
查看>>
KeepAlive随笔
查看>>
你一定要知道的关于Linux文件目录操作的12个常用命令
查看>>
集合文件操作
查看>>
团队开发博客
查看>>
2012-06-04 老男孩老师 “我毕业了”(转)
查看>>
高可用软件heartbeat服务章节目录(草稿)
查看>>
内建校验器2
查看>>
6426C Lab6 部署和配置RMS
查看>>
Windows Server 2012 存储 (四) SMB 对SQL 数据库和Hyper-V的支持
查看>>
CBAC ftp测试
查看>>
2013年全球最佳工作
查看>>
web服务器time_wait值过高解决方案
查看>>
Windows 10企业批量部署实战之WDS安装
查看>>