这是一个非常简单的问题,但令人尴尬的是我不知道如何实现这个:\
我有 div 元素,里面有文本框,供用户写评论、回复等...非常标准的概念。包含文本的div有一定的宽度。如果有人在不使用任何空格的情况下编写某些内容,那么当它到达 div 的右边缘时,它不会中断一行,而是继续前进并中断元素。
我只是想知道当它触及用户或不提供的边缘空间时如何使其断行。
提前致谢
This is a very simple question, but embarrassingly enough I am not sure how to implement this :\
I have div elements with text boxes inside them for users to write comments,replies etc... Very standard concept. The div that contains the text is a certain width. If someone where to write something with out using any spaces, instead of breaking down a line when it hits the right edge of the div, it just keeps going and breaks the element.
I am just wanting to know how to make it line break when it hits the edge spaces provided by user or not.
thanks in advance
发布评论
评论(2)
有一个
word-wrap
CSS 属性会强制长单词换行:您可能还想查看
溢出
。There is a
word-wrap
CSS property that will force long words to wrap:You might also want to look into
overflow
.嗯……这是一个有趣的问题。我在想我要做的是实现一个 JavaScript 函数,该函数将“读取”行的长度,如果单个写入块比最大长度长,我会获取 (最大长度 - 1) 的子字符串,在其末尾添加破折号 (-),添加换行符,然后从那里继续。
Hmmmm...This is an interesting problem. I'm thinking what I would do would be to implement a JavaScript function that would "read" the length of lines and if a single block of writing is longer than the max length, I would grab a substring of (max length - 1), append a dash (-) to the end of it, add in a line break, and proceed from there.