views:

43

answers:

3

I'd like to have the following div tag display a tool-tip on mouse hover. But, it displays it as a single line. How can I get it to display several lines?

<div title="Have a nice<br />day">blah</div>
A: 

Short of replacing the entire thing with elements generated with JS (or ugly CSS hacks) and positioned with CSS, you can't, at least not reliably.

If I remember rightly, some browsers will render a new line if you have a literal new line in the element, while others will render the unprintable character symbol. It is possible that this might need the entity for a new line instead. Either way - avoid this as having the unprintable character symbol is more than a little suboptimal.

If you have that much content, it probably isn't suitable for a tooltip anyway.

David Dorward
A: 

You might want to look into some javascript tooltips.

Dismissile
+1  A: 

it seems that modern browsers will show tooltip on new line after carriage return symbol:

<!-- i've pressed Enter after word "line" -->
<div id="myDiv" title="first line
multiline">Hello world!</div>

Or you can try set value by javascript:

var myDiv=document.getElementById('myDiv'); 
myDiv.title = "first line \n multiline";
Pavel Morshenyuk
I ended up setting the title and doing a replace in jQuery. Thanks!
jinsungy