모바일 코딩
모바일 텍스트 인풋 자동 확대 방지
Disable Auto Zoom in Input “Text” tag - Safari on iPhone
https://stackoverflow.com/questions/2989263/disable-auto-zoom-in-input-text-tag-safari-on-iphone
I made an HTML page that has an <input>
tag with type="text"
. When I click on it using Safari on iPhone, the page becomes larger (auto zoom). Does anybody know how to disable this?
The browser will zoom if the font-size is less than 16px
and the default font-size for form elements is 11px
(at least in Chrome and Safari).
Additionally, the select
element needs to have the focus
pseudo-class attached.
input[type="color"],
input[type="date"],
input[type="datetime"],
input[type="datetime-local"],
input[type="email"],
input[type="month"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="text"],
input[type="time"],
input[type="url"],
input[type="week"],
select:focus,
textarea {
font-size: 16px;
}
It's not necessary to use all the above, you can just style the elements you need, eg: just text
, number
, and textarea
:
input[type='text'],
input[type='number'],
textarea {
font-size: 16px;
}
Alternate solution to have the input elements inherit from a parent style:
body {
font-size: 16px;
}
input[type="text"] {
font-size: inherit;
}
------------------------------
@media screen and (-webkit-min-device-pixel-ratio:0) {
select:focus,
textarea:focus,
input:focus {
font-size: 16px;
background: #eee;
}
}
New: IOS will still zoom, unless you use 16px on the input without the focus.
@media screen and (-webkit-min-device-pixel-ratio:0) {
select,
textarea,
input {
font-size: 16px;
}
}
----------
You can prevent Safari from automatically zooming in on text fields during user input without disabling the user’s ability to pinch zoom. Just add maximum-scale=1
but leave out the user-scale attribute suggested in other answers.
It is a worthwhile option if you have a form in a layer that “floats” around if zoomed, which can cause important UI elements to move off screen.
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
------------
Add user-scalable=0 to viewport meta as following
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
-------------------------
화면 사이즈 고정, 스크로링 방지
If your website is properly designed for a mobile device you could decide not allow scaling.
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />