Why does mobile Safari cut off the text in an input form?

回眸只為那壹抹淺笑 提交于 2021-01-28 11:57:26

问题


Why does an input form on mobile Safari have more padding inside it and push the text to the right so it gets cut off?

I set the width of the input field at 20px which is plenty for the desktop web but on mobile it needs >26px.

^ Desktop Safari Web Input Form ^

^ Mobile iOS Safari Input Form ^


CSS

.phone-input {
    width: 20px;
    text-align: center;
    font-size: 16px !important;
    height: 1.75em;
    //border: 0;
    outline: 0;
    background: transparent;
}

HTML

'<div class="phone-field">'+
     '(<input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-" autofocus="autofocus"><input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-"><input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-">)   '+
     '<input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-"><input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-"><input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-"> - '+
     '<input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-"><input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-"><input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-"><input class="phone-input" name="phone-input" type="tel" size="1" maxlength="1" placeholder="-">'+
'<\/div>'

回答1:


It took me hours to figure out, but the solution is simple:

Just use padding: 0;

(Mobile safari adds a default padding to input fields)



来源:https://stackoverflow.com/questions/31860787/why-does-mobile-safari-cut-off-the-text-in-an-input-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!