:active在IE8中不起作用

时间:2012-05-02 19:41:04

标签: html css internet-explorer-8 css-selectors

:活动代码适用于所有浏览器,除了IE8 (不是9)。我已经看过其他类似的问题,并尝试了不同的方法。这是代码:

HTML:

<div id="main" style="color:white;font-family:Georgia">
   <div id="button" onmouseup="someFunction()"></div>
   <!-- other things -->
</div>

CSS:

#button
{
  position: relative;
  width: 241px;
  height: 41px;
  background-image:url("images/buttonStatic.png");
  display: none;
}

#button:hover
{
  background-image:url("images/buttonHover.png");
}

#button:active
{
  background-image:url("images/buttonActive.png");
}

按钮显示正确,当我将鼠标悬停在第二个按钮上时会更改第二个按钮,但是当我点击它时不会更改为第三个按钮。

2 个答案:

答案 0 :(得分:1)

我刚刚在IE8中试过这个,它运行正常。确保您的DOCTYPE规范声明正确<!doctype html>,并且可能尝试添加类似<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>的IE兼容性元标记。

在旁注中,您不应该使用<DIV>元素作为这样的按钮。您应该使用<button><a>来抑制行为。

修改

这是我的代码......

<!doctype html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
        <title>Active Button</title>
        <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?3.5.0/build/cssreset/cssreset-min.css&3.5.0/build/cssfonts/cssfonts-min.css"/>
        <style type="text/css">
            .button {
                padding: 4px 12px;
                border: solid #555 1px;
                background-color: #ddd;
                }
            .button:hover {
                background-color: #eee;
                }
            .button:active {
                background-color: #09c;
                color: #fff;
                }

            .frame {
                padding: 2em;
                }
        </style>
    </head>
    <body>
        <div class="frame">
            <button class="button">I'm a Button</button>
        </div>
    </body>
</html>

答案 1 :(得分:0)

您的代码很好,这是IE8中的已知错误(抱歉,不一致)。

相关问题