简体   繁体   English

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

[英]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.

相关问题 当鼠标悬停在标签上并随后恢复正常状态时,如何使标签变粗体 - how to make a label go bold when a mouse go over it and back to normal afterwards 将鼠标悬停在组合框项目上时如何更改标签文本? - how to change label text when I hover mouse over a combobox item? 如果我单击或将鼠标悬停在文本上,如何制作工具提示或弹出窗口 - How to make tool tip or popupwindow if i click or mouse over on text 单击标签内的鼠标时如何移动表格? C# - How to make a form move when mouse is clicked within a label ? C# 对于C#中的Tchart,如何使标记提示在鼠标悬停时同时显示系列名称和标签值 - For Tchart in C#, how to make markstip show out both series name and label value when mouse over 在鼠标悬停时使标签下划线 - Making label underline on mouse hover 如果标签宽度不适合C#Windows窗体应用程序中的文本宽度,如何使标签中的文本像(选取框)一样移动? - How can i make the text in the label move like in (marquee) if the label width not fit the text width in C# windows form application? 当我在她身上移动鼠标时,如何放大图片? - How to make picture bigger when i move the mouse on her? 当鼠标单击标签并向上移动鼠标然后在组框内停止移动时,我们如何移动标签 - How we move a label when mouse click on it and when mouse key up then stop moving inside a group box 如何:通过鼠标位置从标签获取文本索引? C# - How to: Get text index from label by mouse position? C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM