ngbTooltip 根据内容大小调整大小

huangapple go评论105阅读模式
英文:

ngbTooltip Resizing Depending on the Content

问题

我已经在我的Angular应用中使用ng-bootstrap v4.2.1创建了一个工具提示(tooltip)。(这个应用使用的是一个旧的代码库)并且对于工具提示的内容,我有一些非常长的句子。我希望这个工具提示的宽度为800px。但是当我指定宽度时,我只看到填充800px的前几个单词。以下是代码:

HTML:

<button type="button" placement="bottom" ngbTooltip="{{Description}}" tooltipClass="description" style="padding: 0; font-size: 1.2em; margin: 0; border: none; background-color: transparent;">
    <i class="fal fa-info-circle" style="color: #757575;"></i>
</button>

TS:

let Description: string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ut dignissim orci, eu feugiat nisi. Aliquam consequat condimentum tortor, ut ullamcorper lacus vestibulum eu. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec id purus in massa imperdiet egestas. Ut purus purus, venenatis a egestas quis, fermentum quis dolor. Duis porttitor, ipsum et molestie fringilla, neque enim bibendum ante, nec tincidunt augue urna vitae risus.";

CSS:

.description .tooltip-inner {
    margin-top: 4px;
    width: 800px;
    word-wrap: break-word;
    text-align: left;
    white-space: normal;
}

我尝试了多种white-space和word-wrap的值,但仍然无法解决问题。

英文:

So I have created a tooltip in my angular app using ng-bootstrap v4.2.1.(working with an old codebase)
And for the content of the tooltip, I have some very long sentences.
I want this tooltip to take 800px width. But when I specify the width, I only see the first few words that fill the 800px.
Here's the code

HTML:

&lt;button type=&quot;button&quot; placement=&quot;bottom&quot; ngbTooltip=&quot; {{Description}}&quot; tooltipClass =&quot;description&quot; style=&quot;padding: 0; font-size: 1.2em; margin: 0; border: none; background-color: transparent;&quot;&gt;
            &lt;i class=&quot;fal fa-info-circle&quot; style=&quot;color: #757575;&quot; &gt;&lt;/i&gt;
        &lt;/button&gt;

TS:

let Description:string = &quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ut dignissim orci, eu feugiat nisi. Aliquam consequat condimentum tortor, ut ullamcorper lacus vestibulum eu. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec id purus in massa imperdiet egestas. Ut purus purus, venenatis a egestas quis, fermentum quis dolor. Duis porttitor, ipsum et molestie fringilla, neque enim bibendum ante, nec tincidunt augue urna vitae risus.

CSS:

.description .tooltip-inner {
    margin-top: 4px;
    width: 800px;
    word-wrap: break-word;
    text-align: left;
    white-space: normal;
}

I tried several white-space and word-wrap values but I still can't figure it out

答案1

得分: 1

如果您希望工具提示的宽度根据内容自动调整,您不需要在CSS中指定固定宽度。

HTML

<button type="button" placement="bottom" ngbTooltip="{{ Description }}" tooltipClass="description" style="padding: 0; font-size: 1.2em; margin: 0; border: none; background-color: transparent;">
  <i class="fal fa-info-circle" style="color: #757575;"></i>
</button>

CSS

.description .tooltip-inner {
  max-width: none;
  word-wrap: break-word;
  text-align: left;
  white-space: normal;
}

在这个CSS中使用了max-width: none;,这允许工具提示根据内容扩展其宽度。**white-space: normal;**属性确保工具提示内的文本换行,并占用必要的宽度以显示所有内容。

英文:

If you want the tooltip's width to automatically adjust based on the content, you don't need to specify a fixed width in the CSS.

HTML

&lt;button type=&quot;button&quot; placement=&quot;bottom&quot; ngbTooltip=&quot; {{ Description }}&quot; tooltipClass=&quot;description&quot; style=&quot;padding: 0; font-size: 1.2em; margin: 0; border: none; background-color: transparent;&quot;&gt;
  &lt;i class=&quot;fal fa-info-circle&quot; style=&quot;color: #757575;&quot;&gt;&lt;/i&gt;
&lt;/button&gt;

CSS

.description .tooltip-inner {
  max-width: none;
  word-wrap: break-word;
  text-align: left;
  white-space: normal;
}

In this CSS using max-width: none;, you're allowing the tooltip to expand its width based on the content. The white-space: normal; property ensures that the text within the tooltip wraps and takes up the necessary width to display all the content

huangapple
  • 本文由 发表于 2023年8月9日 18:40:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866954.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定