Reputation: 59
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()
}
Upvotes: 2
Views: 4791
Reputation: 3365
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).
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
#myspanId:hover {text-decoration: underline;}
Upvotes: 0
Reputation: 11154
Please try with below code snippet.
CSS
.link:hover{
text-decoration:underline;
}
ASPX
<asp:Label CssClass="link"></asp:Label>
Upvotes: 0
Reputation: 184
could you do this with CSS? if so my_element:hover {text-decoration:underline;}
Upvotes: 0
Reputation: 9224
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
http://www.w3schools.com/cssref/sel_hover.asp
You can set text-decoration: underline;
in the class.
Here is a fiddle to show it in action.
.underlineHover:hover{
text-decoration: underline;
}
In the markup you want to add the css class with the cssClass property name
<asp:label id="mylabel" runat="server" text="hover text" cssClass="underlineHover" />
Upvotes: 5