How can you achieve multi-line text truncation with ellipsis in CSS?

Prepare for the CSS Mastery SAD Maintenance and CSA Stand Ups Test. With flashcards and multiple choice questions, ready yourself for the exam with hints and explanations for every question. Ace your exam today!

Multiple Choice

How can you achieve multi-line text truncation with ellipsis in CSS?

Explanation:
Multi-line truncation with an ellipsis relies on turning the element into a box that can limit how many lines are laid out, then hiding the rest. The proven approach uses the WebKit line-clamp technique: you make the element a box with display: -webkit-box, stack lines vertically with -webkit-box-orient: vertical, and specify how many lines to show with -webkit-line-clamp: N, while hiding the overflow. In browsers that support it, this combination yields an ellipsis after the last visible line. Other options fail because single-line truncation uses white-space: nowrap; text-overflow: ellipsis, which doesn’t affect multiple lines. The third option relies on non-existent properties for this effect. The fourth uses line-clamp without the required -webkit-box setup, so it won’t reliably clamp multiple lines across browsers.

Multi-line truncation with an ellipsis relies on turning the element into a box that can limit how many lines are laid out, then hiding the rest. The proven approach uses the WebKit line-clamp technique: you make the element a box with display: -webkit-box, stack lines vertically with -webkit-box-orient: vertical, and specify how many lines to show with -webkit-line-clamp: N, while hiding the overflow. In browsers that support it, this combination yields an ellipsis after the last visible line.

Other options fail because single-line truncation uses white-space: nowrap; text-overflow: ellipsis, which doesn’t affect multiple lines. The third option relies on non-existent properties for this effect. The fourth uses line-clamp without the required -webkit-box setup, so it won’t reliably clamp multiple lines across browsers.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy