How to make :active state work in IE?

前端 未结 1 1460
别那么骄傲
别那么骄傲 2021-01-12 06:27

I have a button in my html form and need to change it\'s background image when it is clicked using css. it works perfect in FF but it seems that IE doesnt support :act

相关标签:
1条回答
  • 2021-01-12 06:45

    This is a known bug in earlier versions of IE (I think they solved it in IE8). I usually solve this (as well as the corresponding "hover" problem) with javascript. I attach two event handlers to the element -- "mousedown" to set an additional class (something like "button-active") and "mouseup" to remove the class. In jQuery it would be something like this:

    $('.button').mousedown(function() { $(this).addClass('button-active'); });
    $('.button').mouseup(function() { $(this).removeClass('button-active'); });
    

    Then, just add that class to the css rule, like so:

    .button:active, .button-active {
        background-position: center bottom;
    }
    

    A little ugly, yes, but what do you expect -- it's Internet Explorer. It can't be pretty.

    0 讨论(0)
提交回复
热议问题