[英]How to make label text underline when i move mouse over it, and then make the label text normal on mouse leave
I tried to make label text underlined when I move mouse over it. 当我将鼠标移到标签文本上时,我试图使标签文本带有下划线。 I used the following code.
我用下面的代码。
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()
}
This has to be done client side not server side. 这必须在客户端而不是服务器端完成。 You may want to add a css class to the label with a hover selector
您可能需要使用悬浮选择器将css类添加到标签
http://www.w3schools.com/cssref/sel_hover.asp http://www.w3schools.com/cssref/sel_hover.asp
You can set text-decoration: underline;
您可以设置
text-decoration: underline;
in the class. 在课堂里。
Here is a fiddle to show it in action. 这是一个小玩意儿,以展示它的实际效果。
http://jsfiddle.net/xNxDf/ http://jsfiddle.net/xNxDf/
.underlineHover:hover{
text-decoration: underline;
}
In the markup you want to add the css class with the cssClass property name 在标记中,您要添加具有cssClass属性名称的css类
<asp:label id="mylabel" runat="server" text="hover text" cssClass="underlineHover" />
could you do this with CSS? 你能用CSS做到这一点吗? if so my_element:hover {text-decoration:underline;}
如果是这样,则my_element:hover {text-decoration:underline;}
Please try with below code snippet. 请尝试使用以下代码段。
CSS CSS
.link:hover{
text-decoration:underline;
}
ASPX ASPX
<asp:Label CssClass="link"></asp:Label>
Label
controls surround their content with the <span>
tags (Unless you use the AssociatedControlID
property, in which case a Label
control will render a <label>
tag). Label
控件的内容用<span>
标签包围(除非您使用AssociatedControlID
属性,否则Label
控件将呈现<label>
标签)。
So you can simply create a style for the tag and it will apply to your labels. 因此,您可以简单地为标签创建样式,并将其应用于您的标签。
span:hover {text-decoration: underline;}
if you want to work with a specific span id, then you can mention the span id in your style 如果您要使用特定的范围ID,则可以在样式中提及范围ID
#myspanId:hover {text-decoration: underline;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.