محمد اشرف
محمد اشرف

Reputation: 59

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()     
}

Upvotes: 2

Views: 4791

Answers (4)

NoviceProgrammer
NoviceProgrammer

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

Jayesh Goyani
Jayesh Goyani

Reputation: 11154

Please try with below code snippet.

CSS

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

ASPX

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

Upvotes: 0

jksloan
jksloan

Reputation: 184

could you do this with CSS? if so my_element:hover {text-decoration:underline;}

Upvotes: 0

Smeegs
Smeegs

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.

http://jsfiddle.net/xNxDf/

.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

Related Questions