简体   繁体   中英

How can I add line break to html text without using any html tag

I want to insert a line break into my profile text on a website, which only allows text to be inserted, so I can not use any html tag.

I would like to know if there in any way to insert line break just like inserting spaces or tabs using ASCII codes?

There isn't. You can enter eg a LINE FEED character as 
 , but it won't help: by HTML rules, it will still be taken just as yet another whitespace character, and any sequence of whitespace characters is equivalent to one SPACE in normal HTML content. You cannot override the HTML rules for processing characters by the characters themselves (only by HTML markup or by CSS).

I think you are looking for codes like ' 'and so...
The 'carry return' code is '
'

Maybe what you are looking for is in there: ASCII HTML CODES

You can set the white-space to pre-line - this will then respect carriage returns.

p {
    white-space: pre-line;
}
<p>Hello,\r\nGoodbye!</p>

Will render:

Hello,
Goodbye!

You probably can't add an arbitrary line break. However, you can influence where a line break occurs if the text is to be rendered inside a container that is not long enough to display the text as a single line. Just use non-breaking spaces at the right places in the text.

Let's suppose the text contains sentences and it is going to be broken to several lines and you want a line break to occur before a certain sentence. Then use non-breaking spaces instead of regular spaces in the sentence. The specific sentence will then possibly not fit on the current line and will be rendered on a new line:

The text is to be rendered in this box. Let's force a line break now.
This•text•starts•on•a•new•line as it will not fit on the previous line without breaking the text
(• stands for &nbsp;).

You can use the <pre> tag when sending the email. Inside this tag textual line breaks are shown as actual line breaks in html.

 <p> this is a text with line breaks </p> <pre> this is a text with line breaks </pre>

在 mailto 正文中,这创建了一个没有任何问题的新行:%0D

尝试\\n从你想要断线的地方开始。

您和其他阅读本文的人可能会使用它

%0A

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM