How to wrap the textarea text of css and html
This article is about how the textarea text of css and html is displayed in new lines. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The text I want to enter in textarea, when displayed on a web page, is displayed in the same format as it was typed.
Textarea input problem
The input box shows something like this: two lines of text are wrapped.
Clipboard.png
1. Html, if you write as follows:
{{$article- > content}}
The display result is shown in the screenshot: the two lines of text will not wrap.
Clipboard.png
2. Add a white-space:pre to html
. pre-text {
White-space:pre
}
The html code is as follows:
{{$article- > content}}
The result is shown in the screenshot below: two lines of text will wrap, but will exceed the outside div
. pre-text {
White-space:pre-wrap
Word-wrap:break-word
Word-break:break-all
}
Text saved with textarea in the background contains line breaks, but generally does not show line breaks when the page is displayed.
Textarea solution
The reason is that the newline character (\ r\ n) saved by textarea is not recognized by html
Method 1. Use style to solve the problem:
. pre-text {white-space:pre-wrap;}
Method 2. Use a script or daemon to deal with newline characters, and directly replace newline characters with br tags.
FunctionfixText (text) {varreplaceRegex=/ (\ n\ r |\ r\ n |\ r |\ n |\ r |\ n) / Gentlementtext | |'; returntext.replace (replaceRegex, ");}
Thank you for reading! This is the end of the article on "how to wrap the textarea text of css and html". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!