简体   繁体   English

将缩进应用于文本区域的每个第一行

[英]Applying indent to each first line of paragraph of text area

I want to apply indention to each paragraph of text area as user types in. I used following code: 我想将缩进应用于文本区域的每个段落作为用户类型。我使用以下代码:

<textarea rows="1" style="height:1em; text-indent:-50px; padding-left:50px;" cols="25" html="true" id="text" >Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum</textarea>

However it applies to only first line of the textarea and not to every first line of new paragraph. 但是它仅适用于textarea的第一行而不适用于新段落的每一行。 Can we achieve this by css? 我们可以用css实现这个目标吗? or any javascript code? 或任何JavaScript代码?

Thanks in advance 提前致谢

If you replace the style attribute by style="text-indent: 50px" , then the paragraphs will have a first-line indent of 50px. 如果用style="text-indent: 50px"替换style属性,则段落的第一行缩进为50px。

It's just so that there is only one paragraph in the textarea. 这只是因为textarea中只有一个段落。 The data there is processed as plain text, and there is no way to indicate a paragraph break. 那里的数据被处理为纯文本,并且无法指示段落中断。 Leaving an empty line means just an empty line within a block of text treated as one paragraph. 留空行意味着在作为一个段落处理的文本块中只有一个空行。

If you want an input area with paragraph breaks, you need to use a normal element like div with the contenteditable attribute (possible, but requires a different approach, eg if you want data to be sent to a server, you need to copy it into a hidden field). 如果你想要一个带分段符的输入区域,你需要使用一个普通元素,比如divcontenteditable属性(可能,但需要一个不同的方法,例如,如果你想将数据发送到服务器,你需要将它复制到一个隐藏的领域)。

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

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