Semantic-UI: Add line break in tooltip
Asked Answered
D

5

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)

Diaconate answered 9/2, 2018 at 7:41 Comment(0)
J
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

Jasisa answered 9/2, 2018 at 12:9 Comment(1)
thanks, I take this solution. As this needs Javascript, I edited your answer to accept itDiaconate
J
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

Jasisa answered 9/2, 2018 at 13:0 Comment(0)
J
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

Jasisa answered 9/2, 2018 at 12:9 Comment(1)
thanks, I take this solution. As this needs Javascript, I edited your answer to accept itDiaconate
P
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

Punishable answered 21/10, 2019 at 8:51 Comment(0)
I
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.

Instable answered 1/7, 2020 at 15:32 Comment(0)
E
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
}
Epilate answered 7/7, 2023 at 22:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.