在 CSS 中设置图像按钮 - image:active

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12543697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:13:59  来源:igfitidea点击:

Setting an image button in CSS - image:active

css

提问by user1666411

I'm trying to replace the submit button with an image by defining it in a class="myButton"and change the styles in CSS. the myButton:activedoesn't seem to work when being clicked.

我试图通过在 a 中定义它class="myButton"并更改 CSS 中的样式来用图像替换提交按钮。在myButton:active似乎没有工作被点击时。

Here is my CSS:

这是我的 CSS:

.myButton{
    background:url(./images/but.png) no-repeat;
    cursor:pointer;
    border:none;
    width:100px;
    height:100px;
}

myButton:active {
     background:url(./images/but2.png) no-repeat;
}

HTML code:

HTML代码:

<input class="myButton" type="submit" value="">

回答by Mr_Green

Check this link. You were missing .before myButton. It was a small error. :)

检查此链接。你失踪.之前myButton。这是一个小错误。:)

.myButton{
    background:url(./images/but.png) no-repeat;
    cursor:pointer;
    border:none;
    width:100px;
    height:100px;
}

.myButton:active  /* use Dot here */
{   
    background:url(./images/but2.png) no-repeat;
}