(This is similar to the (also unanswered) question #3430506, but applies to input tags instead of HTML5 elements.)
On <input type="submit"> buttons, the iPhone/mobile Safari browser adds padding to the left and right. This doesn't happen on the desktop version, nor any other mobile/desktop Webkit browsers I've tried. It appears to add the font-size in px to each side (i.e. 14px font means total width is 14px + width of text + 14px).
Currently I'm trying the following to remove it:
/* webkit user-agent stylesheet uses input[type="submit"] */
form input[type="submit"] { /* more specific to override webkit */
-webkit-appearance:none;
-webkit-border-radius:0px;
margin:0;
padding:0;
border:0;
display:block;
}
I've seen lots of responses about using -webkit-appearance:none... this makes no difference. Neither does removing rounded corners. I made a page to demo how the desktop version renders various -webkit-appearance objects; all have -webkit-border-radius:0 and the above code applied.
(Safari Mobile screenshot for those without an iPhone:)
deleri.com/safari.png
While I'd love to know why this bug occurs, right now I'm more concerned about fixing it. I've tried every type of display/overflow/box-sizing/-webkit-anything-/width:auto/text-indent option imaginable, and can't fix it by manually setting the width (final width needs to be percentage-based, and the strange padding still applies). I'm starting to wonder if it's some obscure property, or if the user agent stylesheet isn't being overwritten. Any thoughts?
form input #submit { /* more specific to override webkit */
-webkit-appearance:none;
-webkit-border-radius:0px;
margin:0;
padding:0;
border:0;
display:block;
}
Do you have control over the form? aka: did you manually enter the form?
If so add either a id or class tag to it
<input type="submit" id="submit" value="submit">
then adjust your css to
form input #submit { /* more specific to override webkit */
-webkit-appearance:none;
-webkit-border-radius:0px;
margin:0;
padding:0;
border:0;
display:block;
}
If you try setting the padding to an enormous value, say 100px, you'll notice that the top and bottom padding grow, while again left and right stays at the default value, in mobile Safari. So I suppose it's safe to assume that this quite simple counts as a bug in the webkit routines of iOS, and there is no direct solution unless Apple fixes the problem.
A workaround would be to create a DIV that looks like whatever you want it to, and add an onclick handler that submits your form. No need to ever use a real submit button.
我现在的建议是检查 Mobile Safari 的版本。如果他们运行的是最新版本(或者修复了此错误的版本或更高版本),他们将获得带有按钮的页面。如果没有,他们可以获得一个带有用于制作按钮的替代标签的页面。在我的页面上,这看起来不太好,而且有点尴尬,但我已经在检查基于该网站的移动或桌面版本的浏览器,所以这并不算太多。
希望这有帮助。
I ran into this bug today when my mom told me that a page I had made was missing text on her old iPhone 3G. Sure enough, I fired up my wife's old 3G we have lying in a drawer someplace, and the text on one of my buttons is being pushed off to the side because Safari is inserting some giant spacing.
The good news is that in the latest update (don't know exactly what, but I've got an updated iPhone 4), this bug has been fixed.
Bad news is that if users don't update their browsers, I can't find any way around it outside of just not using the tag.
My advice for right now is to check the version of Mobile Safari. If they're running the latest version (or whichever version fixed this bug or higher), they get the page with the button. If not, they can get served a page with alternate tags used to make the buttons. On my page this doesn't look as nice, and it's a little awkward, but I'm already checking browsers based on mobile or desktop versions of the site, so this isn't too much on top of that.
发布评论
评论(5)
您可以控制表单吗?又名:您是否手动输入表格?
如果是这样,请添加 id 或 class 标签,
然后将 css 调整为
Do you have control over the form? aka: did you manually enter the form?
If so add either a id or class tag to it
then adjust your css to
我遇到了类似的问题,我注意到当我将背景设置为渐变而不是简单的背景颜色时,我的问题得到了解决。
这在某种程度上忽略了填充值
下面的代码为我解决了提交按钮上的填充问题。
I had a similar issue and I noticed that my issue was resolved when I set the background to a gradient instead of just plain background-color.
This somehow just ignored the padding values
The code below resolved the padding issue for me on submit buttons.
如果您尝试将内边距设置为一个很大的值(例如 100 像素),您会注意到顶部和底部内边距会增大,而左侧和右侧的内边距在移动 Safari 中再次保持为默认值。因此,我认为可以肯定地认为,这个非常简单的问题算作 iOS 的 webkit 例程中的一个错误,并且除非 Apple 修复该问题,否则没有直接的解决方案。
解决方法是创建一个看起来像您想要的任何 DIV,并添加一个提交表单的 onclick 处理程序。无需使用真正的提交按钮。
If you try setting the padding to an enormous value, say 100px, you'll notice that the top and bottom padding grow, while again left and right stays at the default value, in mobile Safari. So I suppose it's safe to assume that this quite simple counts as a bug in the webkit routines of iOS, and there is no direct solution unless Apple fixes the problem.
A workaround would be to create a DIV that looks like whatever you want it to, and add an onclick handler that submits your form. No need to ever use a real submit button.
今天,当我妈妈告诉我,我制作的页面在她的旧 iPhone 3G 上缺少文本时,我遇到了这个错误。果不其然,我打开了我妻子放在抽屉里的旧 3G,我的一个按钮上的文字被推到了一边,因为 Safari 插入了一些巨大的间距。
好消息是,在最新的更新中(不知道具体是什么,但我有更新的 iPhone 4),这个错误已经得到修复。
坏消息是,如果用户不更新他们的浏览器,除了不使用标签之外,我找不到任何解决方法。
我现在的建议是检查 Mobile Safari 的版本。如果他们运行的是最新版本(或者修复了此错误的版本或更高版本),他们将获得带有按钮的页面。如果没有,他们可以获得一个带有用于制作按钮的替代标签的页面。在我的页面上,这看起来不太好,而且有点尴尬,但我已经在检查基于该网站的移动或桌面版本的浏览器,所以这并不算太多。
希望这有帮助。
I ran into this bug today when my mom told me that a page I had made was missing text on her old iPhone 3G. Sure enough, I fired up my wife's old 3G we have lying in a drawer someplace, and the text on one of my buttons is being pushed off to the side because Safari is inserting some giant spacing.
The good news is that in the latest update (don't know exactly what, but I've got an updated iPhone 4), this bug has been fixed.
Bad news is that if users don't update their browsers, I can't find any way around it outside of just not using the tag.
My advice for right now is to check the version of Mobile Safari. If they're running the latest version (or whichever version fixed this bug or higher), they get the page with the button. If not, they can get served a page with alternate tags used to make the buttons. On my page this doesn't look as nice, and it's a little awkward, but I'm already checking browsers based on mobile or desktop versions of the site, so this isn't too much on top of that.
Hope this helps.
这可能是一个愚蠢的建议,但如果问题出在哪里,
您可以尝试将其更改为
“哪个做同样的事情但可能没有错误”?
This might be a daft suggestion, but if the problem is with
could you try changing it for
Which does the same thing but might not have the bug?