Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to wrap the textarea text of css and html

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report