效果图
文本撑满时
![](https://i-blog.csdnimg.cn/blog_migrate/dc3fed8ec0c7b8b9f105c46dd365f605.png)
初始化时
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2f5a86c74405ccdd600766bcdc45e141.png)
码
contenteditable="true"
设为可编辑状态
<div
contenteditable="true"
placeholder="评个小论吧!"
class="textarea"
></div>
<style>
.textarea {
min-height: 36px;
max-height: 120px;
overflow-y: scroll;
outline: none;
background: rgba(111, 111, 111, 0.1);
scrollbar-width: none;
-ms-overflow-style: none;
}
.textarea:empty:before {
content: attr(placeholder);
color: #999;
}
.textarea:focus:placeholder-shown {
content: none;
}
</style>
用作领域
- 用户评论框,textarea无法满足我们正常需求,只能输文本,不能插入图片。
- 这种时候就可以用此类方法创建文本编辑框,还可以插入emjon表情,图片等等