html - 保留文本区域中的换行符

标签 html css textarea line-breaks

我有一个带有文本区域的表单,我想在输出内容时保留用户输入的换行符。

例如,如果我在 textarea 中写:

Here is a sentence. Here is another. here is one more.

This is a new paragraph. Here is a new sentence. Here is another.

我想要相同的输出但:

Here is a sentence. Here is another. here is one more. This is a new paragraph. Here is a new sentence. Here is another.

如何保留换行符?

最佳答案

一般只需要添加

  • white-space: pre-line; 将空格修剪为单个空格

  • white-space: pre-wrap; 所有空白保留

到元素的样式 (CSS),您希望在其中呈现带有换行符的文本。

关于html - 保留文本区域中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30593103/

相关文章:

html - 所有图像排成一行,或所有图像都在彼此下方

html - 两行而不是单行的 Angular 重复

javascript - JS console.log() 显示我的函数遍历了所有 if 语句,但被操作的元素没有改变

javascript - 如何将 html 从当前页面附加到另一个页面?

css - * { 盒子尺寸 : border-box; } : To border-box or not to border-box all elements?

textarea - 将 RTE 添加到 Salesforce 文本区域

jquery - 如何使用 jQuery 监听文本区域中的拖放纯文本?

php - 直接从 .js 或通过 .php 加载 javascript 源代码

html - 如何将 Bootstrap 4 导航栏中的品牌标志设置到左边缘?

binding - Ember.TextArea 通过 Handlebars 助手设置输入