views:

417

answers:

4

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

+1  A: 

Am I wrong in assuming that this question more likely belongs to Doctype?

Valeriu Paloş
A: 

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?

hellweaver666
Thanks for the suggestion, but unfortunately it's the same bug; see the question #3430506 linked above.
pixi
+1  A: 

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.

Eric J. Francois
I ended up using straight <a> links with a JS handler to submit onClick... it may not work in the final release, but it's a good temp fix. Thanks! (Fingers crossed that Apple fixes that bug soon.)
pixi
A: 

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;
}
Erik
I do have control over the form and tried a mix of both ID's and classes when styling; neither worked. (Made it as specific as possible with no luck.)
pixi