当我将鼠标移到它上面时,如何使标签文本下划线,然后在鼠标离开时使标签文本正常

时间:2013-07-01 13:02:18

标签: c# asp.net

当我将鼠标移到它上面时,我试图使标签文字加下划线。我使用了以下代码。

private void Q1lbl_MouseMove(object sender, MouseEventArgs e)
{
    var font = Q1lbl.Font;
    Q1lbl.Font = new Font(font, FontStyle.Underline);
}
private void Q1lbl_MouseLeave(object sender, EventArgs e)
{
    font.Dispose()     
}

4 个答案:

答案 0 :(得分:5)

这必须在客户端而不是服务器端完成。您可能希望使用悬停选择器

将css类添加到标签中

http://www.w3schools.com/cssref/sel_hover.asp

您可以在课程中设置text-decoration: underline;

这是一个显示它在行动的小提琴。

http://jsfiddle.net/xNxDf/

.underlineHover:hover{
    text-decoration: underline;
}

在标记中,您要添加带有cssClass属性名称

的css类
<asp:label id="mylabel" runat="server" text="hover text" cssClass="underlineHover" />

答案 1 :(得分:0)

你可以用CSS做到这一点吗?如果是这样my_element:hover {text-decoration:underline;}

答案 2 :(得分:0)

请尝试使用以下代码段。

CSS

.link:hover{
text-decoration:underline;
}

ASPX

<asp:Label CssClass="link"></asp:Label>

答案 3 :(得分:0)

Label控件使用<span>标记围绕其内容(除非您使用AssociatedControlID属性,在这种情况下,Label控件将呈现<label>标记)。

因此,您只需为代码创建样式,它就会应用于您的标签。

span:hover {text-decoration: underline;}

如果您想使用特定的跨度ID,那么您可以在样式中提及跨度ID

#myspanId:hover {text-decoration: underline;}
相关问题