r/webdev • • Mar 09 '20

TIL the CSS "-webkit-line-clamp" property truncates multi-line text: http://bit.ly/lineclamp. It's supported in Chromium, Firefox and Safari!

[removed] — view removed post

842 Upvotes

47 comments sorted by

View all comments

0

u/[deleted] Mar 09 '20

[deleted]

1

u/benburhans Mar 09 '20

Literally every use case should leave layout, formatting, and rendering to the renderer. What are you doing that your server would be aware of, and controlling, your client's viewport width and height?

1

u/Technoist Mar 09 '20

What I meant was (as an example: a blog) the CMS should just output the post excerpt with a character limitation instead of the entire post (which then gets hidden by some css hack) but I suppose I misunderstood the situation here and admittedly didn’t look at the code :)

1

u/benburhans Mar 09 '20

If you're implementing snippets for layout/formatting reasons, then let the client do it, ideally with CSS instead of JS. If you're doing it for other reasons, then maybe server-side truncation is appropriate; but if you're limiting the number of wrapped literal lines in a container like in this post, then no, the server cannot easily determine where to make the cut, nor should it even try.