webkit line-clamp (multi-line ellipsis) not working with direction rtl

ぐ巨炮叔叔 提交于 2019-12-22 07:45:15

问题


Webkit has the property -webkit-line-clamp which supports a multi-line ellipsis.

Take a look at this demo (on a webkit browser of course) and this CSS-tricks article

.wpr {
  overflow: hidden;
}
.clamp2 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  height: 3.6em;
  /* I needed this to get it to work */
}
<div class="wpr">
  <div class="clamp2">
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
    ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
    augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem.
    Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit
    litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.

  </div>
</div>

So far so good.

The problem is when I add direction:rtl - for right-to-left languages - the -webkit-line-clamp ceases to work - DEMO

Markup

<div class="wpr">
  <div class="clamp3">
  Text
  </div>
</div>

CSS

.wpr
{
  overflow: hidden;
  direction: rtl /* <-- When adding this property ellipsis doesn't work anymore */
}

.clamp3 {
    display: -webkit-box;
    -webkit-line-clamp: 3; /* Maximum of 3 lines of text */
    -webkit-box-orient: vertical;  
    height: 3.6em;
}

.wpr
{
  overflow: hidden;
  direction: rtl;
}

.clamp2 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;  
    height: 3.6em; /* I needed this to get it to work */
}
<div class="wpr">
  <div class="clamp2">
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
  
  </div>
</div

Is this a webkit bug?

Are there any work-arounds?


回答1:


AFAIK ellipsis with direction: rtl only works on one line. E.g.:

.ellipsis-rtl {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: rtl;
}

FWIW, you misspelled direction in your example.



来源:https://stackoverflow.com/questions/20043121/webkit-line-clamp-multi-line-ellipsis-not-working-with-direction-rtl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!