40

In my Angular app (I'm on version 4.3.1) I'm adding a CSS ellipsis after multiple lines.
For this, I use the following css code in Sass.

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

For some reason, the box-orient line simply gets removed from the styling by the transpile, causing the ellipsis to not work. This seems to happen in Angular and Ionic apps.

Paul van den Dool
  • 3,020
  • 3
  • 20
  • 44
  • 1
    https://developer.mozilla.org/en-US/docs/Web/CSS/box-orient is an old syntax version and requires flexbox – Paulie_D Sep 11 '17 at 10:33
  • 1
    I know it's deprecated, but it still works when adding ellipsis on the nth line of a paragraph. And in my case, it's safe to use because all users use the same browser. – Paul van den Dool Sep 15 '17 at 07:18
  • Why are there two `display` rules? Isn't enough to use `display: -webkit-box` only? – smartmouse May 23 '19 at 10:12
  • `display: block` is a fallback. A `div` has `display:block` by default, but if you were to use a span it would have `display: inline-block` by default. In this case I think I wanted to have the `display` set to `block`. – Paul van den Dool Jun 05 '19 at 14:10

5 Answers5

85

Wrapping -webkit-box-orient in the following autoprefixer code seems to solve the issue.

.ellipsis {
    display: block;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
    /* autoprefixer: off */
}
Always Helping
  • 14,316
  • 4
  • 13
  • 29
Paul van den Dool
  • 3,020
  • 3
  • 20
  • 44
28

Similar solution as was previously presented, but one less line if that's your thing:

.ellipsis {
    /* autoprefixer: ignore next */
    -webkit-box-orient: vertical;
    display: block;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
}
jdgower
  • 1,172
  • 15
  • 18
10

The following work for me.

.ellipsis {
/* autoprefixer: off */
-webkit-box-orient: vertical;
/* autoprefixer: on */
display: block;
display: -webkit-box;
-webkit-line-clamp: 2;
overflow: hidden;
text-overflow: ellipsis;

}

Alan-Wen
  • 109
  • 1
  • 3
6

For SCSS:

/*! autoprefixer: ignore next */
-webkit-box-orient: vertical;
rolznz
  • 779
  • 9
  • 16
4

None of the answers worked for me.

My solution was to put the -webkit-box-orient: vertical as inline-styling and the rest as a class. Not elegant, but it works.

jonask
  • 679
  • 2
  • 6
  • 21