iOS WebKit browsers and auto-zooming form controls
3192 단어 browser
본문
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 for
textarea
, 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.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
웹 브라우저의 localStorage에서 데이터를 관리하는 방법은 무엇입니까? JavaScript, React JS로 설명하십시오.localStorage는 JavaScript 사이트 및 앱이 만료 날짜 없이 웹 브라우저에 키-값 쌍을 저장할 수 있도록 하는 속성입니다. LocalStorage 데이터는 localStorage에서 데이터를 삭제할 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.