Intro...
There is a property text-overflow: ellipsis; in CSS.
It makes the sentence add ellipsis(...) at the end of the word or sentence.
However, elipsis is sometimes not applied in some cases.
In this post, we will discuss experiences where elipsis was not applied.
If you want to know more about elipsis, click the link below ππΌ
URL:
https://jay-h-blog.vercel.app/posts/CSS/text-overflow
Error While Using Library
Problem
In general, when configuring the web, using text-overflow: ellipsis; usually doesn't cause problems. (Of course, IE does cause problems.) However, in my case, it was not a problem caused by IE because it does not deal with IE.
In HTML+CSS+JS structure, an image was on a webpage and text was stacked on top of the image. It was necessary to take a screenshot with elipsis(...) at the end of the text.
To automate screenshots of web pages, I used a library called HTML2Canvas. But, Ellipsis did not apply to photographs taken through HTML2Canvas.
The below image is an example.
If looking at the picture above, in the red box, there is no ellipsis at the end of the text even though text-overflow: ellipsis; white-space: nowrap; overflow: hidden is applied.
Solution
Nothing is yet certain about this matter. But, the problem can be solved.
Looking at the text with ellipsis through the inspector. There is no ellipsis(...).
html2canvas is not "taking" a screen that looks like we are taking a picture. It is to scrape and reconstruct the codes constituting the screen, and convert the reconstructed codes into images. In other words, it is not taking a picture, but taking a code.
This is probably why ellipsis doesn't be applied when screenshots are taken using html2canvas.
So.. How to Deal With This Error?
The simplest way to solve this problem is to use JS.
It's to cut off a character at a certain length, delete it after it, and paste it with Ellipsis(...).
1// Cuts a character based on the specific length (jquery) 2var title = $('._title_bar'); 3var title_content = $(title).text(); 4 5if (title_content.length > 10) { 6 $(title).text(title_content.substring(0,10) + '...'); 7} 8 9// (js) 10var title = document.querySeletor('._title_bar'); 11 12if (title_content.length > 10) { 13 title.innerText = `${title.substring(0,10)}...`; 14}
If multiple languages are used or numbers and English are mixed, awkwardness may occur if the characters are cut off in length. This is because each language has different space.
For example, 10 Korean letters and 10 English letters occupy different spaces.
In this case, if specifying the width and cut the letters based on when the height changes, the awkwardness mentioned above can be supplemented a little.
1// HTML code 2<div style="width: 30px">Lorem ipsum dolor sit amet</div> 3 4// JS code 5var title = $('._title_bar'); 6var title_content = $(title).text(); 7 8if ($(title).outerHeight() > 16) { 9 $(title).text(title_content.substring(0,10) + '...'); 10}
URL:
https://github.com/niklasvh/html2canvas/issues/324


