views:

759

answers:

2

I stumbled upon the weirdest behavior in IE6/FF3 when setting custom height (even if it's the same as default) on a button. The following code should demonstrate that while the two buttons are of same height, their padding is different for some implicit reason and cannot be controlled in any fathomable way:

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>weird-padding-change</title>
  <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
  <style>
  input {
    vertical-align: middle;
    width: 100px;
    /* no effect: */
    padding-top: 0;
    padding-bottom: 0;
  }
  </style>
</head>

<body>

<div style="background:red">
<input type="button" style="height:24px;" value="_24px_"/>
<input type="button" value="_Def. Height_"/>
</div>

</body>
</html>

If anyone has any idea how to explain this or, even better, make the padding equal - please tell me.

Thanks.

A: 

I had a little play with it in FF3 and found if you add:

padding-bottom:2px;

to the custom height button no matter what height you make the button its text will still line up with the default height button's text. Unlike other elements, adding padding to the input button does not add to its overall height or width if its got a set height or width.

As for an explanation, hell knows, maybe its something to do with how the browser renders input buttons to prevent them looking horribly pixelated as they are enlarged.

Wayne Austin
That fixes it, thanks :) Still doesn't make it less confusing though, because the focus rectangle on the default button is unpadded at bottom - so it can't be that custom height negates default padding-bottom of 2px. Can't really imagine how this or that padding would affect the rendering process either. *sigh* the quirks...
krukid
A: 

I myself had trouble with setting the dimensions of buttons, and here's how I found the way to tame them: http://www.sitepoint.com/forums/showthread.php?t=547059

Wabbitseason
Thanks, but I try to avoid those -moz classes.
krukid