如何使:在IE工作状态的工作? [英] How to make :active state work in IE?

查看:163
本文介绍了如何使:在IE工作状态的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,在我的HTML表单,需要改变它的背景图片使用CSS被点击时它。它的工作原理完美在FF但似乎IE犯规支持:主动状态。

下面是我的code:

HTML

 <按钮类='按钮'>点击ME< /按钮>

CSS:

  .button {
    宽度:118px;
    高度:33px;
    背景:网址(/images/admin/btn.png)不重复顶部中心;
    边界:无;
    概述:无;
}
.button:积极{
    背景位置:底部中心;
}


解决方案

这是在早期版本的IE浏览器的一个已知的bug(我认为他们解决了它IE8)。我通常用JavaScript解决这个问题(以及相应的悬停的问题)。我附上两个事件处理程序的元素 - 鼠标按下设置一个附加的类(如按钮,激活的东西)和鼠标松开去掉的类。在jQuery的将是这样的:

  $('按钮')的mousedown(函数(){$(本).addClass(按钮主动');});
$('按钮')的mouseup(函数(){$(本).removeClass(按钮主动');});

然后,刚才那类添加到CSS规则,就像这样:

  .button:主动,.button活跃{
    背景位置:底部中心;
}

有一个难看一点,是的,但你能指望什么 - 这是IE浏览器。它不能是pretty。

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 :active state.

Here is my code:

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;
}

解决方案

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.

这篇关于如何使:在IE工作状态的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆