css:div实现textarea文本框那种可以自适应文字高度的
说明:
- 模拟textarea可编辑的效果: contenteditable="true"
- 高度自适应:给个最小高度属性min-height和默认高度属性 _height即可
HTML代码:
<div class="test_box" contenteditable="true"></div>
CSS代码
.test_box {
width: 400px;
min-height: 120px;
max-height: 300px;
_height: 120px;
margin-left: auto;
margin-right: auto;
padding: 3px;
outline: 0;
border: 1px solid #a0b3d6;
font-size: 12px;
word-wrap: break-word;
overflow-x: hidden;
overflow-y: auto;
_overflow-y: visible;
}