英文:
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:
<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;
}
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
<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;
}
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论