Можно ли использовать переполнение текста: многоточие на многострочном тексте? - PullRequest
58 голосов
/ 04 июля 2011

У меня есть p -tag с конкретными width и height.Я хочу использовать text-overflow:ellipsis, чтобы получить ..., если текст в теге слишком длинный.Можно ли решить с помощью CSS на многострочном тексте?

Ответы [ 12 ]

0 голосов
/ 07 апреля 2016

Эй, вы можете сделать это, используя css.

Для Chrome и Safari

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

Для Firefox и Internet Explorer

* styles for '...' */ 
.block-with-text {
  /* hide text if it more than N lines  */
  overflow: hidden;
  /* for set '...' in absolute position */
  position: relative; 
  /* use this value to count block height */
  line-height: 1.2em;
  /* max-height = line-height (1.2) * lines max number (3) */
  max-height: 3.6em; 
  /* fix problem when last visible word doesn't adjoin right side  */
  text-align: justify;  
  /* place for '...' */
  margin-right: -1em;
  padding-right: 1em;
}
/* create the ... */
.block-with-text:before {
  /* points in the end */
  content: '...';
  /* absolute position */
  position: absolute;
  /* set position to right bottom corner of block */
  right: 0;
  bottom: 0;
}
/* hide ... if we have text, which is less than or equal to max lines */
.block-with-text:after {
  /* points in the end */
  content: '';
  /* absolute position */
  position: absolute;
  /* set position to right bottom corner of text */
  right: 0;
  /* set width and height */
  width: 1em;
  height: 1em;
  margin-top: 0.2em;
  /* bg color = bg color under block */
  background: white;
}
0 голосов
/ 02 июня 2015

Как указывалось ранее, есть странный способ сделать это с помощью веб-набора, размещенного Дэвидом ДеСандро:

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

ссылка http://dropshado.ws/post/1015351370/webkit-line-clamp

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...