<输入类型=“提交”> Safari 移动设备上的填充错误?

发布于 2024-09-15 03:43:22 字数 1172 浏览 2 评论 0 原文

(这类似于(也未回答)问题 #3430506,但适用于输入标签而不是 HTML5 元素。 )

上按钮时,iPhone/移动 Safari 浏览器会在左侧和右侧添加内边距。这种情况不会发生在桌面版本上,也不会发生在我尝试过的任何其他移动/桌面 Webkit 浏览器上。它似乎在每一侧添加了以 px 为单位的字体大小(即 14px 字体意味着总宽度为 14px + 文本宽度 + 14px)。

目前我正在尝试以下方法来删除它:

/* 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;
}

我已经看到很多关于使用 -webkit-appearance:none 的回复...这没有什么区别。删除圆角也不行。我制作了一个页面来演示桌面版本如何渲染各种 -webkit-appearance 对象;全部都有 -webkit-border-radius:0 并应用上述代码。

尝试在桌面版 Safari 上查看这些内容,然后在 iPhone 上查看:
http://deleri.com/test.html

(Safari Mobile 屏幕截图,供没有 iPhone 的用户使用:)
deleri.com/safari.png

虽然我很想知道为什么会出现这个错误,但现在我更关心修复它。我已经尝试了可以​​想象到的每种类型的显示/溢出/框大小/-webkit-anything-/width:auto/text-indent选项,并且无法通过手动设置宽度来修复它(最终宽度需要是百分比-基于,并且奇怪的填充仍然适用)。我开始怀疑它是否是一些晦涩的属性,或者用户代理样式表是否没有被覆盖。有什么想法吗?

(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.

Try viewing these on desktop Safari then iPhone:
http://deleri.com/test.html

(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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

爱你是孤单的心事 2024-09-22 03:43:22

您可以控制表单吗?又名:您是否手动输入表格?

如果是这样,请添加 id 或 class 标签,

<input type="submit" id="submit" value="submit">

然后将 css 调整为

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;
}
鹊巢 2024-09-22 03:43:22

我遇到了类似的问题,我注意到当我将背景设置为渐变而不是简单的背景颜色时,我的问题得到了解决。

这在某种程度上忽略了填充值

#submit{
    background:#a0b9dc;
    padding:9px 35px;
 }

下面的代码为我解决了提交按钮上的填充问题。

#submit{
    background:#a0b9dc;
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #A0B9DC));
    background: -o-linear-gradient(bottom, #A0B9DC 0%);
    background: -moz-linear-gradient(bottom, #A0B9DC 0%);
    background: -webkit-linear-gradient(bottom, #A0B9DC 0%);
    background: -ms-linear-gradient(bottom, #A0B9DC 0%);
    background: linear-gradient(to bottom, #A0B9DC 0%);
    padding:9px 35px;
}

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

#submit{
    background:#a0b9dc;
    padding:9px 35px;
 }

The code below resolved the padding issue for me on submit buttons.

#submit{
    background:#a0b9dc;
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #A0B9DC));
    background: -o-linear-gradient(bottom, #A0B9DC 0%);
    background: -moz-linear-gradient(bottom, #A0B9DC 0%);
    background: -webkit-linear-gradient(bottom, #A0B9DC 0%);
    background: -ms-linear-gradient(bottom, #A0B9DC 0%);
    background: linear-gradient(to bottom, #A0B9DC 0%);
    padding:9px 35px;
}
农村范ル 2024-09-22 03:43:22

如果您尝试将内边距设置为一个很大的值(例如 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.

彼岸花似海 2024-09-22 03:43:22

今天,当我妈妈告诉我,我制作的页面在她的旧 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.

甜嗑 2024-09-22 03:43:22

这可能是一个愚蠢的建议,但如果问题出在哪里,

<input type="submit" /> 

您可以尝试将其更改为

<button type="submit" />

“哪个做同样的事情但可能没有错误”?

This might be a daft suggestion, but if the problem is with

<input type="submit" /> 

could you try changing it for

<button type="submit" />

Which does the same thing but might not have the bug?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文