在我的Angular
2/4 应用程序中,我使用ng-bootstrap
及其组件NgbTooltip
。
假设以下HTML
代码段
<div class="col-sm-8 text-ellipsis"
ngbTooltip="'A very long text that does not fit'"
placement="top"
container="body">
A very long text that does not fit
</div>
有给定的习惯CSS
.text-ellipsis {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
我对我的实现还不满意,也许有人可以帮我找到一个优雅的解决方案来解决我的问题:
假设文本不适合div
,那么它将被截断并按预期附加“...”,并且工具提示显示在div
. 这对这种情况很好,但是当内容很短时,它看起来很丑:
<div class="col-sm-8 text-ellipsis"
ngbTooltip="'1.jpg'"
placement="top"
container="body">
1.jpg
</div>
现在工具提示仍然显示在 div 的顶部中心,但在文本的右侧(因为它很短但div
仍然是全宽)。
我认为我可以通过使用span
元素并在其上设置工具提示而不是div
:
<div class="col-sm-8 text-ellipsis">
<span
ngbTooltip="'A very long text that does not fit'"
placement="top"
container="body">
A very long text that does not fit
</span>
</div>
但是这种解决方法引发了另一个问题,如下所示:
现在的问题是跨度被截断,但实际上比div
. 工具提示呈现在.span
而不是div
.
任何“顺利”的想法如何使它更好?非常感谢您的意见。