views:

69

answers:

2

While we ask a question, SO shows related questions. If we hover on the questions the content is displayed as a tooltip which contains linebreaks, indentations etc. What technique SO uses for it? How to display tooltips wit the formatting?

Other than, jquery/javascript is there any simple way to achieve it?

Was just wondering, should i ask this on Meta?

+4  A: 

It is just a title attribute on the hyperlink, plain and simple.

<a href="..." title="The value is approximately
        3.14159265
    but for simplicity you can always round it
    to exactly 3.0">What is the value of Pi?</a>

In IE, Chrome & Safari, it honors the line breaks a bit more strictly than say Firefox or Opera.

scunliffe
Title attribute is correct
Jack Marchetti
I knew title attirbute, problem was the linebreaks on FF. How to satisfy FF and Opera?
San
There isn't much you can do (re:Firefox) the value used to be truncated at a very short length (IIRC something like 32 chars) and it took years to get Mozilla to increase it. I've seen several jQuery and similar plugins that will take the title attribute, and hook in some magic to overlay a div with the formatted content of the title attribute.
scunliffe
I came through those kind of jQuery code ideas. But, when I use those, size of file becomes double. :-( So, I was wondering was there any simple solutions or minimal code..
San
Do you have jQuery or a similar library already installed? if so, a simple tooltip would likely be possible w/o inserting a whole plugin.
scunliffe
Yes, I use jquery. How to achieve a simple tooltip?
San
Seems like SO uses the same method which works fine on IE and Chrome but FF. Thanks, scunliffe!
San
A: 
Sergey Osypchuk
It can. But, not all the browsers display it. Tried the same on FF. No linebreak at all! I believe it just works on IE only. I want FF and Chrome too.
San
I am using chrome and it has line breaks for me....
Sergey Osypchuk
Yes, it does on chrome. Thanks, Sergey! Is there any solution for FF?
San