views:

4270

answers:

5

Hello.

I want my submit buttons + links to look as buttons and the same in all browsers.

Firefox 3.5 plays nice. But IE6,7,8 have all different looks. Can you help me with that (apparently) simple task?

<!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>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Crossbrowser css submit button, links</title>
    <style type="text/css">
     button {
      background:#FFE900;
      color:#000;
      padding:3px 5px 3px 5px;
      border:1px solid #000;
     }
     input {
      background:#FFE900;
      color:#000;
      padding:3px 5px 3px 5px;
      border:1px solid #000;
     }
     a {
      background:#FFE900;
      color:#000;
      padding:3px 5px 3px 5px;
      border:1px solid #000;
      text-decoration:none;
     }
    </style>
</head>
<body>
<a href="#">Buy now</a>
<input type="submit" value="Buy now" />
<button type="submit">Buy now</button>
</body>
</html>
A: 

If you want a uniform appearance, you'll need to use an image submit button.

chaos
I sort of hoping to use css for that. You know, lighter website, easier to change, better support for changing text inside the button.
Cudos
+1  A: 

For the button instead of type="submit" use type="image".

For instance:

<button type="image" src="path_to_your_image.png">Buy now</button>

For link you can use css to set the background of your link:

background-image: url('path_to_your_image.png');
czuk
+2  A: 

You can replace the Submit button with an image the same way you do it with a background-image for a link. Simply get rid of the background and border, put the background-url in the input selector, and give it the right width and height.

input{
    background-color: white;
    border: 0;
    background-image: url('blah.png');
}
Chacha102
Cudos
Chacha102
One useful way to get rid of the text is (in a conditional IE comment) apply the style line-height: 0; as long as your input button has a width and a height you'll be golden.
andykram
A: 

You could always use a JavaScript framework to replace the element with one that is more stylable or use MSIE's conditional comments for browser-specific styling.

Sad truth is cross-browser pixel perfection seems impossible with pure CSS and buttons.

Alan
A: 

I take it you do understand that you'll never get them to look exactly the same, since even in Firefox 3.5 they don't look exactly the same for me.

And apart from purely the style, they'll always have different behavior. For example, buttons will respond differently to tabbing or clicking (some browsers "depress" the text), buttons won't show the URL they point to in contrast with links, and you can select the text of a link, but not that of a button.

You can fix the most glaring differences on IE6 and 7 quite easily, though.

Add this to the CSS for your buttons (<button> and <input>):

overflow: visible;

You can put it inside a stylesheet for IE6/7 only, though this shouldn't affect any other browser, since visible is actually the default value. But for some reason this fixes the inconsistencies with the padding, compared to that for the link, on IE6 and IE7.

And add the following to the CSS for the link. All browsers need this, to make the link behave more like a block element, just like the buttons:

display: inline-block;
mercator