5

I want to have line breaks in my tooltip:

<span data:data-tooltip="line 1 ...\n 
                              line 2 ...">

I tried several proposals from here: Add line break within tooltips

Nothing did the trick. I use it without Javascript (v.2.2)

Gibin Ealias
  • 2,751
  • 5
  • 21
  • 39
pme
  • 14,156
  • 3
  • 52
  • 95

5 Answers5

5

If you require to use the no JS version of tooltip, you may adjust the width of the tooltip and set the white-space to normal. PEN

Gibin Ealias
  • 2,751
  • 5
  • 21
  • 39
4

You may use data-html instead of data-tooltip with a <br/> tag.

<div class="ui icon button" data-html="<p>First line <br/> Second line</p>">
  <i class="add icon"></i>
</div>

This solution needs Javascript, see PEN

pme
  • 14,156
  • 3
  • 52
  • 95
Gibin Ealias
  • 2,751
  • 5
  • 21
  • 39
  • 1
    thanks, I take this solution. As this needs Javascript, I edited your answer to accept it – pme Feb 09 '18 at 18:15
2

Because i found this first via google, its good to complete:

You can also use &#xa; in combination with white-space: pre; like stated here: CSS data attribute new line character & pseudo-element content value

terraloader
  • 311
  • 2
  • 10
2

This is similar to @terraloader's answer, but I wanted to give it more context.

This is the best non-Javascript solution for adding a line break in a Semantic UI tooltip.

Add the following rule to your stylesheet:

[data-tooltip]::after {
    white-space: pre;
}

And then, in your data-tooltip attribute, use the &#xa; *

Here's how:

<span data-tooltip="If you want to remove&#xa;this item from the&#xa;list, click here.">
    <i class="red delete icon"></i>
</span>

* This is the HTML-Encoded Line Feed character (using a hexadecimal value). You can also use the decimal notation &#10;. Either way, they are functionally equivalent to \n which is a Line Feed.

pbarney
  • 2,529
  • 4
  • 35
  • 49
0

Depending on what version of Semantic-ui you could jsut update the main style sheet; looks like min has white-space:norap in it. Here I have updated it to white-space:pre and then will try using the in line in the tool tip text:

[data-tooltip]:after{
    pointer-events:none;
    content:attr(data-tooltip);
    position:absolute;
    text-transform:none;
    text-align:left;
    white-space:pre;
    font-size:1rem;
    border:1px solid #d4d4d5;
    line-height:1.4285em;
    max-width:none;
    background:#fff;
    padding:.833em 1em;
    font-weight:400;
    font-style:normal;
    color:rgba(0,0,0,.87);
    border-radius:.28571429rem;
    box-shadow:0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.15);
    z-index:1
}