如何在asp.net中为c#中的按钮编写悬停样式?我写了这些代码,但我不知道如何为它写悬停?
button1.Style[" border-style"] = "solid";
button1.Style["background-color"] = "#063a83";
button1.Style[" border-width"] = "3px";
button1.Style[" color"] = "White";
button1.Style[" font-family"] = "Tahoma";
button1.Style[" border-color"] = "Gray";
button1.Style[" border-radius"] = "10px";
button1.Style[" background-image"] = "url(../images/products/zoom2.png)";
button1.Style[" background-repeat"] = "no-repeat";
button1.Style[" padding"] = "10px";
button1.Style["Cursor"] = "pointer";
我想写这个悬停:
.btn:hover
{
background-color :#202020 ;
cursor:pointer;
}
向您添加CssClass
按钮,如下所示:
Button button2 = new Button();
button2.Text = "buy";
button2.ID = ddr[2].ToString();
button2.CssClass = "btn"; //add a css class
button2.Click += new System.EventHandler(detail_Click);
Panelproduct.Controls.Add(button2);
然后在css样式表中为该类添加样式,如下所示:
.btn{
border-style: solid;
background-color: #063a83;
/*more styles*/
}
.btn:hover{
background-color :#202020 ;
cursor:pointer;
}
这是我的代码:
Button button2 = new Button();
button2.Text = "buy";
button2.ID = ddr[2].ToString();
button2.Style[" border-style"] = "solid";
button2.Style["background-color"] = "#063a83";
button2.Style[" border-width"] = "3px";
button2.Style[" color"] = "White";
button2.Style[" font-family"] = "Tahoma";
button2.Style[" border-color"] = "Gray";
button2.Style[" border-radius"] = "10px";
button2.Style[" background-image"] = "url(../images/products/zoom2.png)";
button2.Style[" background-repeat"] = "no-repeat";
button2.Style[" padding"] = "10px";
button2.Style["Cursor"] = "pointer";
button2.Click += new System.EventHandler(detail_Click);
Panelproduct.Controls.Add(button2);