131

Possible Duplicate:
How can I use a carriage return in a HTML tooltip?

I'd like to know if it's possible to force a newline to show in the tooltip when using title property of a TD. something like

<td title="lineone \n linetwo \n etc...">

Can this be done?

Community
  • 1
  • 1
spence91
  • 77,143
  • 9
  • 27
  • 19

9 Answers9

186

This should now work with Internet Explorer, Firefox v12+ and Chrome 28+

<img src="'../images/foo.gif'" 
  alt="line 1&#013;line 2" title="line 1&#013;line 2">

Try a JavaScript tooltip library for a better result, something like OverLib.

RealHowTo
  • 34,977
  • 11
  • 70
  • 85
41

One way to achieve similar effect would be through CSS:

<td>Cell content.
  <div class="popup">
    This is the popup.
    <br>
    Another line of popup.
  </div>
</td>

And then use the following in CSS:

td div.popup { display: none; }
td:hover div.popup { display: block; position: absolute; }

You will want to add some borders and background to make the popup look decent, but this should sketch the idea. It has some drawbacks though, for example the popup is not positioned relative to mouse but relative to the containing cell.

Petr Tuma
  • 522
  • 5
  • 8
  • 1
    This should really be voted up higher. No need to get a jQuery plugin. This plus some extra styling and positioning should be a fantastic option for anybody. I'm going to use it right now, working for a gigantor company that you all know. – vbullinger Mar 19 '12 at 22:17
  • 2
    I think you need to update the css in case there is table inside a table to make css work properly. Use `td > div.restoredbpopup { display: none; } td:hover > div.restoredbpopup { display: block; position: absolute; }` – Radek Apr 25 '12 at 02:15
27

The Extensible Markup Language (XML) 1.1 W3C Recommendation say

« All line breaks MUST have been normalized on input to #xA as described in 2.11 End-of-Line Handling, so the rest of this algorithm operates on text normalized in this way. »

The link is http://www.w3.org/TR/2006/REC-xml11-20060816/#AVNormalize

Then you can write :

<td title="lineone &#xA; linetwo &#xA; etc...">
Stéphane Klein
  • 856
  • 1
  • 11
  • 20
7

Using &#xA; Works in Chrome to create separate lines in a tooltip.

4

Using &#013; didn't work in my fb app. However this did, beautifully (in Chrome FF and IE):

<img src="'../images/foo.gif'" title="line 1&lt;br&gt;line 2">
Erez Cohen
  • 1,507
  • 2
  • 16
  • 25
4

This should be OK, but is Internet Explorer specific:

<td title="lineone
linetwo 
etc...">

As others have mentioned, the only other way is to use an HTML + JavaScript based tooltip if you're only interested in the tooltip. If this is for accessibility then you will probably need to stick to just single lines for consistency.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ady
  • 4,736
  • 2
  • 22
  • 20
  • sorry, i realise that my question wasn't very descriptive of the solution i was looking for... I'm looking for a way for newlines to show up on the tooltip, i tried this and it doesn't work in IE or firefox. – spence91 Oct 29 '08 at 11:22
  • Appologies, this should work OK for internet explorer, however I just checked with FireFox, and it looks like the line breaks are ignored. – Ady Oct 29 '08 at 11:24
  • 2
    Apologies again, as it does indeed work in IE, but not firefox – spence91 Oct 29 '08 at 11:25
  • 1
    @spence91, it also works on Google Chrome and Safari. – Derek 朕會功夫 Jan 05 '12 at 02:20
3

I use the jQuery clueTip plugin for this.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
2

If you're looking to put line breaks into the tooltip that appears on mouseover, there's no reliable crossbrowser way to do that. You'd have to fall back to one of the many Javascript tooltip code samples

Gareth
  • 133,157
  • 36
  • 148
  • 157
1

The jquery colortip plugin also supports <br> tags in the title attribute, you might want to look into that one.

baik
  • 993
  • 2
  • 14
  • 21