2

Test page:

<!DOCTYPE html>
<html>
    <head>
        <title>button border hover test</title>
        <style type="text/css">
            input
            {
                border: 0;
                padding: 0;
            }

            input:hover
            {
                background-color: fuchsia;
            }
        </style>
    </head>
    <body>
        <form>
            <input type="button" value="input element" /><br>
        </form>
    </body>
</html>

The background colour does not change. If you set the padding to anything higher than 0, the background colour does change. I'm not seeing this behaviour in Firefox.

Having a padding of 1px isn't disruptive to the layout, but does anyone know of a way to make this work with 0 padding?

3
  • 1
    Can you use the <button type="submit"> element? It will work in IE8. labs.findsubstance.com/2009/05/21/… Commented Mar 3, 2011 at 18:16
  • Unfortunately the project is built on a framework that does not allow <button>. It's an XML BI framework where a 'Button' element translates to <input type="button">. Commented Mar 4, 2011 at 0:18
  • Pretty sure: IE8 only supports :hover on <a> elements. Commented Apr 14, 2011 at 18:43

2 Answers 2

3

There are two possible solutions.

  1. Use a <button> element instead.
  2. Use padding. But even then, sometimes the hover doesn't work.

Some relevant information from http://www.sitepoint.com/forums/showthread.php?769898-button-vs.-input-type-quot-button-quot

<button> can contain HTML, and is easier to style with CSS, which actually gets applied across browsers. However, there are some drawbacks to using it in IE. IE doesn't properly detect the value attribute (and uses the tag's content instead as the value), and all values are sent to the server, whether or not the button is clicked. This makes using it as a a little tricky.

<input type="submit"> doesn't have any value or detection issues. However, you can't add HTML like with and can only use the value tag. It's also harder to style, and the styling doesn't always respond well across browsers.

Sign up to request clarification or add additional context in comments.

Comments

2

Welcome to the club. This was driving me crazy. I have a table with buttons in the last column. When you hover over a row, the background changes. If you hover over the button in the row, the text color on the button changes as well as the row background. I had 0 padding on the buttons. All this works great in FF with no problems.

In IE8, a whole nuther story. The row hover worked great but when you hovered over the button in the row, nothing happened. The row background didn't change and the button text color didn't change (99.99% of the time).

I played with this and finally realized what was going on. It seems to be that hover doesn't work while over button text. I added 20px of padding on each side of the text on the button. If I slide my cursor down the buttons in the padded area (not touching the text) it worked as well as FF. As soon as I slide the cursor down the middle of the buttons (through the button text), it breaks.

Go figure. I HATE IE!!!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.