【问题标题】::active does not work in IE8:active 在 IE8 中不起作用
【发布时间】:2012-05-12 07:52:11
【问题描述】:

:active 代码适用于所有浏览器,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");
}

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

【问题讨论】:

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


    【解决方案1】:

    我刚刚在 IE8 中尝试过,效果很好。确保您的 DOCTYPE 规范声明正确 &lt;!doctype html&gt; 并可能尝试放入类似于 &lt;meta http-equiv="X-UA-Compatible" content="IE=Edge"/&gt; 的 IE 兼容性元标记。

    附带说明,您不应该将&lt;DIV&gt; 元素用作这样的按钮。您应该使用 &lt;button&gt;&lt;a&gt; 来抑制行为。

    编辑

    这是我的代码...

    <!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>
    

    【讨论】:

    • 感谢 Brendan,该元标记完美运行!公司所有的电脑都还在运行 IE8,这样不仅解决了这个问题,而且还让其他一些 CSS 元素功能更正常。
    【解决方案2】:

    您的代码很好,这是 IE8 中的一个已知错误(抱歉,存在差异)。

    【讨论】:

    猜你喜欢
    • 2015-12-19
    • 2012-05-23
    • 2015-06-07
    • 2013-05-07
    • 2012-04-03
    • 1970-01-01
    • 2013-05-03
    • 2011-01-17
    • 2011-05-29
    相关资源
    最近更新 更多