zoukankan      html  css  js  c++  java
  • [转]iOS WebKit browsers and auto-zooming form controls

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

  • 相关阅读:
    nyoj592 spiral grid
    ny788 又见Alice and Bob
    hdoj 1166 敌兵布阵 线段数和树状数组
    nyoj228 士兵杀敌(5)插线问线
    nyoj576 集齐卡片赢大奖(一)
    ny269 VF
    AC Again hdoj 1582 搜索
    nyoj123 士兵杀敌(四)树状数组 插线问点
    CRAVAT: Cancer-Related Analysis of VAriants Toolkit
    第二代无创胎儿基因组分析结果
  • 原文地址:https://www.cnblogs.com/freeliver54/p/3651533.html
Copyright © 2011-2022 走看看