【发布时间】:2020-12-11 12:38:16
【问题描述】:
我正在尝试对我的文本区域进行动态调整高度。 我在这里看到了一些解决方案,但它现在对我有用.. 我的代码:
const textArea = document.querySelector("textarea");
const textRowCount = textArea ? textArea.value.split("\n").length : 1;
const rows = textRowCount;
<textarea type="text" className="chat-box" rows={rows} style={{ height: "unset" }} />
css:
.chat-box{
width: 70%;
border-radius: 25px;
border: solid 1px #b7b7b7;
background-color: #eeeeee;
margin-left: 2%;
padding-left: 3%;
padding-right: 3%;
padding-top: 2%;
padding-bottom: 2%;
margin-top:0.5%;
resize: none;
vertical-align: middle;
overflow: hidden;
}
.chat-box:focus{
outline-style: none;
}
.chat-box::-webkit-scrollbar {
width: 2px;
}
.chat-box::-webkit-scrollbar-track {
background: #eeeeee;
border-left: solid 1px #b6bcca;
width: 10px;
}
.chat-box::-webkit-scrollbar-thumb {
background: #7b808b;
border-radius: 3px;
}
我希望通过按“Enter”,rextarea 将多一行(如果可以将其扩大到顶部,那就太好了 - 就像在 whatsapp 计算机应用程序中一样。
【问题讨论】:
-
欢迎来到 Stack Overflow。请看,What should I do when someone answers my question? 也可以通过tour 来熟悉如何使用这个平台。
标签: javascript css reactjs