简体   繁体   English

CSS按钮,默认颜色,悬停颜色和:active颜色更改

[英]CSS Button, default color, hover color and :active color change

first of all there is my button's code; 首先是我按钮的代码;

HTML HTML

<asp:Button Text="Register" ForeColor="#ffffff" BackColor=" #ba04c2" ID="btnReg" CssClass="btnReg" runat="server" OnClick="btnReg_Click" />

CSS CSS

.left-side .fast-reg .alt .btnReg{
 width: 100px;
 height: 40px;
 margin-top: 10px;
 line-height: 40px;
 text-align: center;
 float: right;
 -webkit-transition-duration: 0.4s; 
 transition-duration: 0.4s;

}
.btnReg:hover {
    background-color: #d053f5; 

}

.btnReg:focus {
    background-color: #3e0442; 

}

I want to change the default color for my button, hover color and when it is pressed. 我想更改按钮的默认颜色,悬停颜色以及按下时的颜色。

For example, the color of the button is purple, when cursor will appear on the button and the color will become clear. 例如,按钮的颜色是紫色,当光标出现在按钮上并且颜色将变清晰时。 When the button gets clicked, the color will be more darker. 单击该按钮时,颜色将更深。

I put BackColor="#colorcode" to asp:button part, but when I do that, hover is being deactivated. 我将BackColor="#colorcode"放在asp:button部分,但是当我这样做时,悬停功能被停用。

How can I change the button color while hover and :active function is not being deactivated? hover:active功能未停用的情况下,如何更改按钮的颜色?

When you set the BackColor property of an asp:Button it actually gets rendered in HTML like this: 当您设置asp:ButtonBackColor属性时,它实际上将以HTML呈现,如下所示:

<input type="button" style="background-color: #ba04c2; ..." />

The style attribute that you see in foregoing input element is called inline styling . 在前面的input元素中看到的style属性称为内联样式 And most of the cases inline styling automatically wins over CSS definitions because of the " CSS Specificity ". 而且大多数情况下,由于“ CSS特殊性 ”,内联样式会自动赢得CSS定义。 In CSS world every styling has its own weight and they are applied to an element respectively to that weight. 在CSS世界中,每个样式都有其自己的权重,它们分别应用于该权重的元素。

So, if you want to override an inline style in your CSS you have to force it by adding !important to your CSS definition as follows. 因此,如果您想在CSS中覆盖内联样式,则必须通过在CSS定义中添加!important来强制执行内联样式,如下所示。

.btnReg:hover {
    background-color: #d053f5 !important; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM