强制 TEXTAREA 元素换行的最优雅方式,*不管*有空格 [英] Most elegant way to force a TEXTAREA element to line-wrap, *regardless* of whitespace

查看:41
本文介绍了强制 TEXTAREA 元素换行的最优雅方式,*不管*有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Html Textarea 元素仅在到达空格或制表符时换行.这很好,直到用户输入一个 looooooooooooooooooooooong 足够的单词.我正在寻找一种严格执行换行符的方法(例如:即使它导致loooooooooooo ooooooooooooong").

Html Textarea elements only wrap when they reach a space or tab character. This is fine, until the user types a looooooooooooooooooooooong enough word. I'm looking for a way to strictly enforce line breaks (eg.: even if it results in "loooooooooooo ooooooooooong").

我发现最好的方法是在每个字母后添加一个零宽度的 unicode 空格,但这会破坏复制和粘贴操作.有人知道更好的方法吗?

The best I've found is to add a zero-width unicode space after every letter, but this breaks copy and paste operations. Anyone know of a better way?

注意:我在这里指的是textarea"元素(即:行为类似于文本输入的元素)——不仅仅是一个普通的旧文本块.

Note: I'm referring to the "textarea" element here (i.e.: the one that behaves similarly to a text input) - not just a plain old block of text.

推荐答案

CSS 设置 word-wrap:break-wordtext-wrap:unrestricted 似乎是CSS 3 特性.祝你在当前的实现中找到一种方法来做到这一点.

The CSS settings word-wrap:break-word and text-wrap:unrestricted appear to be CSS 3 features. Good luck finding a way to do this on current implementations.

这篇关于强制 TEXTAREA 元素换行的最优雅方式,*不管*有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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