使用CSS在鼠标悬停时更改ASP.NET按钮的颜色

3
我有一个按钮:
<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;      
}

它不知道为什么不起作用。请让我知道。

6个回答

3
尝试使用ASP.NET控件的CssClass属性。这将直接将LinkButton指向CSS类,而无需使用div标签。例如:
<asp:LinkButton ID="SetThreshold" OnClick="btnSetThreshold_Click" runat="server" CssClass="HeaderBarThreshold">Threshold</asp:LinkButton>

1

这里有一个 JSFiddle 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;
    }

这在Visual Studio 2019中不适用于ASP.NET Web表单。 - Zizzipupp

1
尝试一下这个东西:

.HeaderBarThreshold a:hover
{
    color: Red;      
}

1
在您的Web控件中添加CSS类属性。
<asp:LinkButton CSSClass="HeaderBarThreshold" ID="SetThreshold" OnClick="btnSetThreshold_Click" runat="server">Threshold</asp:LinkButton>

此外,您的CSS也有问题,因为您没有将任何内容分配给“HeaderBarThreshold”类。

0
.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>

0

试一下这个

.HeaderBarThreshold:hover a
{
     color: Red !important; // !important may not be necessary 
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接