简体   繁体   English

-webkit-line-clamp 在 Chrome 上不起作用,除非我在开发人员工具中进行了一些不相关的 CSS 更改

[英]-webkit-line-clamp does not work on Chrome unless I make some unrelated CSS change in developer tools

I am trying to add ellipsis after a certain number of lines in Chrome.我想在 Chrome 中的一定行数后添加省略号。 As suggested in various boards, I used the webkit-line-clamp strategy as below正如各种董事会所建议的那样,我使用了 webkit-line-clamp 策略,如下所示

.line-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;  
   text-overflow: ellipsis;
   overflow: hidden;
}

So I do not see the ellipsis at the end of the fourth line to begin with, but if I go into the developer tools and make some random change to the CSS in the element (say change the margin of the element, or check and uncheck one of the properties above), then the ellipsis is seen.所以我没有看到第四行末尾的省略号,但是如果我进入开发人员工具并对元素中的 CSS 进行一些随机更改(比如更改元素的边距,或者选中和取消选中上述属性之一),则可以看到省略号。 This is similar to what was reported in https://bugs.chromium.org/p/chromium/issues/detail?id=265836 .这类似于https://bugs.chromium.org/p/chromium/issues/detail?id=265836中报告的内容。

Is there a workaround to this issue?这个问题有解决方法吗? I cannot reproduce this issue in a plain html, it seems to only happen in the application for some inexplicable reason.我无法在纯 html 中重现此问题,它似乎只在应用程序中发生,原因不明。

根据 Andyweb 的评论,发布在css-multi line-clamp (ellipsis) 上的解决方案对我有用。

visibility: visible;

有点棘手但工作顺利!

I had this problem where line clamp didn't work but adding word-wrap:break-word in my styles made it work.我遇到了这个问题,换行符不起作用,但在我的样式中添加word-wrap:break-word使它起作用。

I dunno if this is going to help you guys looking for a solution ,hopefully it will though.我不知道这是否会帮助你们寻找解决方案,但希望它会。

Ps: this happened to me when the div that has line clamp style was wrapped inside another div that has ngIf directive applied to it . Ps:当具有线夹样式的 div 被包裹在另一个应用了ngIf指令的 div 中时,这发生在我身上。

My div works when it stand alone but when it's parent div has white-space css, it was be broken.我的 div 在它独立时可以工作,但是当它的父 div 有空白 css 时,它被破坏了。

I fixed by add:我通过添加修复:

    white-space: break-spaces;
    max-height: 35px;

I know this is old, but see MDN .我知道这很旧,但请参阅MDN

" It only works in combination with the display property set to -webkit-box or -webkit-inline-box and the -webkit-box-orient property set to vertical. " 它只能与设置为 -webkit-box 或 -webkit-inline-box 的显示属性以及设置为垂直的 -webkit-box-orient 属性结合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM