views:

91

answers:

5

I noticed that IE sometimes has very large padding around button text. It seems to be proportional to the amount of text the button has. This makes for very ugly buttons.

I am hesitant to make buttons with fixed width because of internationalization issues. Same goes for percent widths.

How has people dealt with this short of styling DIVs like buttons?

+2  A: 

Here is a fix that works for me:

<!--[if IE]>
<style type="text/css">

input { 
  overflow: visible;
  padding-left:2px;
  padding-right:2px;
}

</style>
<![endif]-->
mkoryak
A: 

I never noticed this until your posted this question - but you're right. The amount of padding on the button seems to be a "percentage" of the length of text, which means it gets much wider when you add more text to the button.

If it is just buttons you want to adjust the behaviour on, this works:

input[type='button'] {
 overflow: visible;
}

You don't need to make this conditional as it doesn't affect the button display in other browsers. You could change the rule to be "submit" as well as "button" too. This removes the automatic psuedo-padding entirely and allows you to add your own style rules.

Sohnee
i was under the impression that IE6 does not support those types of selectors (which contain attribute values). am i wrong?
mkoryak
@mkoryak: RIGHT!
Marco Demajo
Hmmm. IE6 didn't get a specific mention in the question.
Sohnee
A: 

I would adjust the padding of the buttons through CSS.

input {
padding: 0; }

Removing the padding will restrict the button size to fit the contents.

Slevin
this doesnt work, as i mentioned in a comment, this adds extra padding to what is already there
mkoryak
A: 

Make sure you add this doctype to the top of your page and it won't do that anymore:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

You can read up on what this does here: http://www.w3.org/TR/xhtml1/ but basically it tells the page what sort of HTML you want to use.

Bertine
But surely this isn't a difference between (X)HTML specs, rather whether the browser decides to use quirks mode or (its attempt at) standards mode. See http://www.quirksmode.org/css/quirksmode.html
Stewart
@Bertime: DOCTYPE and quirks/standard mode does NOT have anything to do with the padding added by IE6 and IE7 around buttons text. Even when in standard mode, and even using a strict DOCTYPE IE6 and IE7 still go on adding more padding araound buttons text.
Marco Demajo
A: 

This makes the trick:

input[type='button'], input[type='submit'] { overflow: visible; }
/* add above also your desired button padding if you want. */

FYI:

  1. If you want you don't have to use IE conditonal comment because this CSS does not disturb the way buttons are displaied on other browsers.
  2. On IE7 works, but IE6 does not support [type='...'] selectors, therefore it's going to ignore this style. For IE6 the only way aroud this is to apply a class to every button and add the same CSS { overflow: visible; } for such class.
  3. IE8 does not need this anymore because they finally fixed this one.
Marco Demajo