Foliotek Developer Blog

A simple Formatted ToolTip text on hover

The task was to add a formatted “ToolTip” message when hovering on a “More” link. ?On a certain report, some of the names got pretty long. ?Instead of wrapping text on the report, the desire was to simply truncate the name, then allow the user to see the entire name by hovering over the “More” link. ?However, we wanted more than just the built-in ToolTip look.

I’ve seen JavaScript implementations of this, but I was looking for a simpler solution. ?This is what I came up with:

The Mark-up

?<%# (Eval("Name").ToString().Length > 65) ? Eval("Name").ToString().Substring(0, 60) + "..." : Eval("Name")%>

<%# (Eval("Name").ToString().Length > 65) ? "More" : "" %> <%# Eval("Name") %>

The CSS

[sourcecode lang="css"]
.showonhover .hovertext { display: none;}
.showonhover:hover .hovertext {display: inline;}
a.viewdescription {color:#999;}
a.viewdescription:hover {background-color:#999; color: White;}
.hovertext {position:absolute;z-index:1000;border:1px solid #ffd971;background-color:#fffdce;padding:11px;width:150px;font-size: 0.75em;}
[/sourcecode]

Comment

The key is the first two lines of the CSS, specifically hiding the .hovertext node until the mouse hovers over the .showonhover node. ?This is a pretty simple solution, but it wasn’t immediately apparent to me, so I thought I’d share it with others who may have the same initial mental block that I had.