CSS Modern multi-line ellipsis

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Thanks a million. I have been looking for an implement of this. Had to use JavaScript to clip. This works too!
Awesome Marvin, Glad it was helpfull!
You're welcome Douglas, glad you enjoyed it
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

A while ago I wrote an article on truncating text with ellipsis, and we used a fail-safe version for the multi-line ellipsis.
Today I'm looking into a more modern and simple approach to solve this truncate problem.
The end result:
The HTML for this assignment is super basic, we just need one big paragraph.
<p>
Morbi rutrum lectus turpis, sit amet sollicitudin eros condimentum vitae. Integer
consequat eros vel tortor tempor, et vulputate turpis pretium. Suspendisse vel metus
sem. Aenean sollicitudin luctus est ac gravida. Curabitur eros tellus, scelerisque sit
amet suscipit consequat, laoreet at quam. Nullam massa ante, tincidunt quis metus ut,
consequat facilisis risus. Orci varius natoque penatibus et magnis dis parturient
montes, nascetur ridiculus mus.
</p>
As you can imagine this is way bigger than just three lines right. Let's see how we can solve this in the modern-day and age.
To get right to it, we'll be using line-clamp to solve this.
Line-clamp will allow us to state how many lines it should cut the text.
p {
width: 200px;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
As you may have spotted, for now, this only works if the display method is webkit-box.
So far this is by far the easiest way to achieve this, but has some odds and ends, like having to use the display format.
I actually was surprised the browser support for this is quite good. Most modern browsers support it out of the box.

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter