簡體   English   中英

當我將鼠標移到標簽文本下划線時如何使其下划線,然后在鼠標離開時使標簽文本正常

[英]How to make label text underline when i move mouse over it, and then make the label text normal on mouse leave

當我將鼠標移到標簽文本上時,我試圖使標簽文本帶有下划線。 我用下面的代碼。

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

這必須在客戶端而不是服務器端完成。 您可能需要使用懸浮選擇器將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" />

你能用CSS做到這一點嗎? 如果是這樣,則my_element:hover {text-decoration:underline;}

請嘗試使用以下代碼段。

CSS

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

ASPX

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

Label控件的內容用<span>標簽包圍(除非您使用AssociatedControlID屬性,否則Label控件將呈現<label>標簽)。

因此,您可以簡單地為標簽創建樣式,並將其應用於您的標簽。

span:hover {text-decoration: underline;}

如果您要使用特定的范圍ID,則可以在樣式中提及范圍ID

#myspanId:hover {text-decoration: underline;}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM