简体   繁体   English

如何在不使用任何 html 标签的情况下向 html 文本添加换行符

[英]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.我想在网站上的个人资料文本中插入一个换行符,它只允许插入文本,所以我不能使用任何 html 标签。

I would like to know if there in any way to insert line break just like inserting spaces or tabs using ASCII codes?我想知道是否有任何方式插入换行符,就像使用 ASCII 代码插入空格或制表符一样?

There isn't.没有。 You can enter eg a LINE FEED character as 
您可以输入例如 LINE FEED 字符作为
 , 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. ,但这无济于事:根据 HTML 规则,它仍将被视为另一个空格字符,并且任何空格字符序列都相当于普通 HTML 内容中的一个空格。 You cannot override the HTML rules for processing characters by the characters themselves (only by HTML markup or by CSS).您不能通过字符本身(只能通过 HTML 标记或 CSS)覆盖处理字符的 HTML 规则。

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也许你正在寻找的是: ASCII HTML CODES

You can set the white-space to pre-line - this will then respect carriage returns.您可以将white-space设置为pre-line - 这将尊重回车。

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.您可以在发送电子邮件时使用<pre>标签。 Inside this tag textual line breaks are shown as actual line breaks in html.在此标签中,文本换行符在 html 中显示为实际换行符。

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

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

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

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

%0A

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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