Truncating Text Inside Elements with CSS or JS

preview_player
Показать описание
There are many times when you need to be able to constrain or limit or truncate text within an HTML element. With CSS there are a couple ways to do this.
I have an older video that explains how you can use the ellipsis and truncate text on a single line using just CSS.
This video explains the -webkit-line-clamp property that can be used to clamping the text in a block element to a specific number of lines. CSS can automatically add the ellipsis here too.
The majority of this video explains how to build a fallback with JavaScript. To be able to do this with JS we need to be able to calculate the approximate width of the average character too. So, the script here delves into some text-metric calculations.

Рекомендации по теме
Комментарии
Автор

I was just trying to do this the other day! Thanks for posting!

astrosticks
Автор

loved it steve as always great work <3

boudyhesham
Автор

Hi Steve 😊😊
What font-family are you using in your VS Code?? I really like it...🙂🙂

hammadahmad
Автор

Hello steve, you make and amazing videos.
Can you please make videos about webpack ? (how to create workflow with js and writing in separate files)

ofekezra
Автор

sir please make videos on react huge request

simple
Автор

In real life the elements will not always be p tags, think of data coming from Api where you have li, and other html tags along. Everyone running to show the easy unreal case but not actually the full solution.

broadshare
visit shbcf.ru