使用 CSS 更改鼠标悬停时 asp.net 按钮的颜色

Change color of an asp.net button on mouse hover using css

本文关键字:net asp 按钮 颜色 悬停 CSS 鼠标 使用      更新时间:2023-09-26

我有一个按钮:

<div class="HeaderBarThreshold">
     <asp:LinkButton ID="SetThreshold" OnClick="btnSetThreshold_Click" runat="server">Threshold</asp:LinkButton>
</div>

我正在尝试更改鼠标悬停时按钮的颜色:

这是我的 css:

.HeaderBarThreshold
{
    padding-left: 10px;
    font-weight: bold;
}
.HeaderBarThreshold:hover
{
    color: Red;      
}

它不知何故不起作用。请让我知道。

尝试使用 ASP.NET 控件的 CssClass 属性。 这将直接将 LinkButton 本身指向 CSS 类,而不必使用div 标签。例如:

<asp:LinkButton ID="SetThreshold" OnClick="btnSetThreshold_Click" runat="server" CssClass="HeaderBarThreshold">Threshold</asp:LinkButton>

这是一个小提琴 http://jsfiddle.net/zpfw7/

    .HeaderBarThreshold
    {
    padding-left: 10px;
    font-weight: bold;
    width:300px;
    height:30px;
    border:1px solid #000;
    text-align:center;
    }
    .HeaderBarThreshold:hover
    {
    color: Red; 
    background:blue;
    }

试试这个东西:

.HeaderBarThreshold a:hover
{
    color: Red;      
}

将 CSS 类属性添加到 Web 控件

<asp:LinkButton CSSClass="HeaderBarThreshold" ID="SetThreshold" OnClick="btnSetThreshold_Click" runat="server">Threshold</asp:LinkButton>

无论如何,您的CSS都是错误的,因为您没有为类"HeaderBarThreshold"分配任何内容。

试试这个

.HeaderBarThreshold:hover a
{
     color: Red !important; // !important may not be necessary 
}
.upda_link {
    font-size: 15px !important;
    color: white;
    font-weight: bolder;
}
.upda_link:hover {
    text-decoration: none;
    color: white;
}
<asp:LinkButton ID="LinkButton1" runat="server" Text="Update" CssClass="upda_link" CausesValidation="false">
</asp:LinkButton>