html - 正确对齐输入内的文本

标签 html css input

我有一个输入类型的文本(也尝试过使用 textarea),我将它的高度设置为 400px,因为我想让它像一个文本框。例如,就像我现在正在输入的那个。文本将换行的位置等等。问题是文本只进入中心并向右滚动,而不是换行。我该如何正确执行?

编辑:好吧,我已经描述过了,但是如果这里是代码:

<input type="text" name="message" id="contact_message" pattern=".{10,}">

CSS:

#contact_message {
    width: 400px;
    height:400px;
}

最佳答案

这里有两个选项:a <textarea>和一个 <div contenteditable> .我建议使用 <textarea> .

textarea {
  height: 400px;
  width: 400px;
  word-wrap: break-word;
  outline: 0;
  border: 1px solid black;
  font-family: Arial, Sans-serif;
  font-size: 20pt;
}
<textarea minlength="10">this is some really long text that should break into new lines whenever this crosses 400 pixels wide and go to the new line ehahoitheiahithahihhoghaohhtoihaoiehhnbieoaihtoai</textarea>

您可以使用 divcontenteditable :

div {
  height: 400px;
  width: 400px;
  font-family: Arial, Sans-serif;
  font-size: 20pt;
  
  }
<div contenteditable>some really long text that should span more than one line when this crosses 400pixels and go into a new line iaoheotheaothoehtoihieothaoihtihiaohtieathioehwaoteahtioehahthahaiohh</div>

关于html - 正确对齐输入内的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42091045/

相关文章:

javascript - 如何让置顶的大图变小,最后粘在置顶?

javascript - 获取不在特定 div 中的所有表单输入

css - 基本字体大小与移动设备

c++ - 在 C++ 中从文本文件读取输入到数组

html - 输入类型 URL - 如果不包含 HTTP,则为 "Please enter a URL"

Python 错误 : IndexError list index out of range

html - 在一行上显示两个元素

html - 页脚内容未正确对齐

javascript - 将样式应用于特定的 v-for 元素

html - Firefox 文本输入截断字母底部