Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect when text wraps?

Is it possible to detect where text wraps?

Lorem ipsum dolor sit amet

lets say that above text wraps after 'dolor' word. How to detect that and insert there some mark of it so it would be Lorem ipsum dolor<div class='wrap-mark'/> sit amet for example?

like image 638
user1785870 Avatar asked Nov 29 '12 14:11

user1785870


1 Answers

I've seen this problem solved a few different ways. One of my favorites involves creating a div that mirrors the width of the container that holds your text. You then print words of your content into faux-container one-by-one, measuring the height of the container along the way. When the height of the container changes, you know you have a line feed/wrap.

Facebook and a few other CMS's use a method like this to grow their textareas to fit the contents of a user's input. I'm sure you could probably glean a few more creative ways to measure your text by researching those techniques, too.

like image 134
Daniel Szabo Avatar answered Oct 12 '22 19:10

Daniel Szabo