是否可以检测文本换行? [英] Is it possible to detect when text wraps?

查看:103
本文介绍了是否可以检测文本换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检测文字包装的位置?

Is it possible to detect where text wraps?


Lorem ipsum dolor sit amet

Lorem ipsum dolor sit amet

让我们说上面的文字换成'dolor'字。如何检测并插入一些标记,所以它将 Lorem ipsum dolor< div class ='wrap-mark'/>

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?

推荐答案

我看到这个问题解决了几种不同的方法。我最喜欢的一个是创建一个div,它反映了容纳你的文本的容器的宽度。然后将您的内容的单词逐个打印到一个容器中,测量容器的高度。当容器的高度改变时,你就知道你有换行符/换行符。

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和一些其他的CMS使用这样的方法增长他们的textareas适合用户输入的内容。我相信你也许可以通过研究这些技术来收集更多创意的方式来衡量你的文字。

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.

这篇关于是否可以检测文本换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆