键入时是否可以使文本框垂直滚动



如何制作可垂直滚动的html文本框,这意味着当键入时达到文本框的宽度时,它会自动触发到下一行(如文本区域但不使用文本区域(?

你可以

这样拥有它。CSS 具有提到的高度和溢出,div 标签上的可内容可编辑属性为 true。希望对您有所帮助。

<style>    
 div.textbox {
   background-color: #ececec;
   height: 100px;
   max-height: 100px;
   width: 200px;  
   overflow-x: hidden;
   overflow-y: scroll;
 }
</style>

<div class="textbox" contenteditable="true">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</div>

简单将div 高度和宽度以及溢出-y 设置为滚动

div{
    height: 200px;
    width: 300px;
    overflow-y: scroll;
}

因此,当您的文本达到 300px 的宽度时,它会转到下一行,根据需要降低高度

不,不可能使 text 类型的input具有多行

您可以使用

此属性使元素可编辑。 它将充当文本框contenteditable="true"

.input {
  width: 300px;
}
<p class="input" contenteditable="true">This is a paragraph. It is editable. Try to change this text.This is a paragraph.</p>

最新更新