5

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?

3
  • I know simple linebreaks work on a few browsers. Also, 
 on some. But I want it to work on all the browsers.
    – San
    Jul 23, 2010 at 16:23
  • I know the use of title attribute too! I just want linebreaks on it.
    – San
    Jul 23, 2010 at 16:30
  • SO's tooltip works fine on IE6 too!
    – San
    Jul 24, 2010 at 8:22

2 Answers 2

6

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.

6
  • I knew title attirbute, problem was the linebreaks on FF. How to satisfy FF and Opera?
    – San
    Jul 23, 2010 at 16:35
  • 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
    Jul 23, 2010 at 16:52
  • 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
    Jul 23, 2010 at 17:02
  • 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
    Jul 23, 2010 at 17:29
  • Yes, I use jquery. How to achieve a simple tooltip?
    – San
    Jul 24, 2010 at 8:23
1

I took this html actually from stackoverflow. Here is no magic here:

Here's a dumb question which I can't find an answer to:
I have a table which contains 20 fields, a few of which are date/time. I am interested in pulling all the fields. I would like to  … ">Selecting fields in SQL Select statements (Dumbest SQL Question)</a>

As you see, title can have line breaks!

2
  • 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
    Jul 23, 2010 at 16:18
  • Yes, it does on chrome. Thanks, Sergey! Is there any solution for FF?
    – San
    Jul 23, 2010 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.