Hướng dẫn php ellipsis - dấu chấm lửng php

I'm not a JS pro, but I figured out a couple ways you could do this.

Nội dung chính

  • Video học lập trình mỗi ngày
  • Sử dụng text-overflow: ellipsis;
  • Bạn có thể xem demo tại đây : codepen.io
  • 1. Sử dụng bộ ba nguyên tử white-space, overflow, text-overflow
  • 2. Kết hợp -webkit-line-clamp với overflow
  • 3. Sử dụng word-break
  • Kết luận

The HTML:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi elementum consequat tortor et euismod. Nam commodo consequat libero vel lobortis. Morbi ac nisi at leo vehicula consectetur.

Then with jQuery you truncate it down to a specific character count but leave the last word like this:

// Truncate but leave last word
var myTag = $('#truncate').text();
if (myTag.length > 100) {
  var truncated = myTag.trim().substring(0, 100).split(" ").slice(0, -1).join(" ") + "…";
  $('#truncate').text(truncated);
}

The result looks like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi elementum consequat tortor et…
elementum consequat tortor et…

Or, you can simply truncate it down to a specific character count like this:

// Truncate to specific character
var myTag = $('#truncate').text();
if (myTag.length > 15) {
  var truncated = myTag.trim().substring(0, 100) + "…";
  $('#truncate').text(truncated);
}

The result looks like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi elementum consequat tortor et…
elementum consequat tortor et euismod…

Or, you can simply truncate it down to a specific character count like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi elementum consequat tortor et euismod…

Hope that helps a bit.

Video học lập trình mỗi ngày

Sử dụng text-overflow: ellipsis;

Bạn có thể xem demo tại đây : codepen.io"Three dots in ES6" nên đừng lầm tưởng đến mức cơ bản đấy.

1. Sử dụng bộ ba nguyên tử white-space, overflow, text-overflow

Sử dụng text-overflow: ellipsis;

Bạn có thể xem demo tại đây : codepen.io

1. Sử dụng bộ ba nguyên tử white-space, overflow, text-overflow

2. Kết hợp -webkit-line-clamp với overflow

3. Sử dụng word-break

Show 

Bạn có thể xem demo tại đây : codepen.io

1. Sử dụng bộ ba nguyên tử white-space, overflow, text-overflow 3 phút đọc

2. Kết hợp -webkit-line-clamp với overflow

3. Sử dụng word-breakdính liền nhau, nhập một đoạn văn bản cực dài cho tiêu đề hoặc bất cứ phần tử nào đó có thể hiển thị text. Và đương nhiên trong quá trình code Front-End (FE) nếu bạn không cover được các trường hợp thực tế có thể xảy ra đó chắc chắn QA sẽ log bug và tặng cho bạn 1 ticket nho nhỏ

Kết luận

1. Sử dụng bộ ba nguyên tử white-space, overflow, text-overflow

2. Kết hợp -webkit-line-clamp với overflow

3. Sử dụng word-break

Kết luận

element {
  white-space: nowrap; 
  overflow: hidden;
  text-overflow: ellipsis; /* text-overflow: clip; */
}

The HTML:

  • Then with jQuery you truncate it down to a specific character count but leave the last word like this:
  • The result looks like this:
  • Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi elementum consequat tortor et…

Or, you can simply truncate it down to a specific character count like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi elementum consequat tortor et euismod…

Hope that helps a bit.

element {
  display: inline-block;
  max-width: 100%;
  
  white-space: nowrap; 
  overflow: hidden;
  text-overflow: ellipsis; /* text-overflow: clip; */
}

2. Kết hợp -webkit-line-clamp với overflow

3. Sử dụng word-breaksố dòng muốn hiển thị, phần nội dung vượt quá sẽ bị ẩn đi và thay thế bởi dấu 3 chấm. Cách sử dụng như sau

element {
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  display: -webkit-box;
}

Kết luận

3. Sử dụng word-break

Kết luận

  • The HTML:any character'
  • Then with jQuery you truncate it down to a specific character count but leave the last word like this:arbitrary points'

Kết luận

The HTML:

Then with jQuery you truncate it down to a specific character count but leave the last word like this:

The result looks like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi elementum consequat tortor et…