我的 html 表单中有一个按钮,需要在使用 css 单击它时更改它的背景图像。它在 FF 中运行完美,但似乎 IE 不支持 :active
状态。
这是我的代码:
HTML:
<button class='button'>Click Me</button>
CSS:
.button {
width: 118px;
height: 33px;
background: url(/images/admin/btn.png) no-repeat center top;
border: none;
outline: none;
}
.button:active {
background-position: center bottom;
}
最佳答案
这是 IE 早期版本中的一个已知错误(我认为他们在 IE8 中解决了它)。我通常用 javascript 解决这个问题(以及相应的“悬停”问题)。我将两个事件处理程序附加到该元素——“mousedown”以设置一个附加类(类似于“button-active”)和“mouseup”以删除该类。在 jQuery 中它会是这样的:
$('.button').mousedown(function() { $(this).addClass('button-active'); });
$('.button').mouseup(function() { $(this).removeClass('button-active'); });
然后,只需将该类添加到 css 规则中,如下所示:
.button:active, .button-active {
background-position: center bottom;
}
是的,有点难看,但您还能期待什么——它是 Internet Explorer。它不可能很漂亮。
关于html - 如何制作:active state work in IE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4057861/