之前在写评论框的时候,留下了一个历史遗留问题:textarea不会自适应高度,可能技术水平不够,当时好像用js,切换input和textarea,实际的操作效果并不友好,今天重写页面的时候,尝试了一个新的想法:textarea自动高度,竟然成功了!拿起我的日记本,赶快记录下来这一激动的时刻!

纯CSS实现微信小程序textarea文本域自动高度-QUI-Notes
1.html

<div class="chat-from flex aifd jcfs">
      <view class="chat-input">
        <textarea cursor-spacing='80' auto-height='{{true}}' adjust-positio="{{false}}" show-confirm-bar="{{false}}"  cols="30" rows="10"></textarea>
      </view>
      <view class="chat-more" bindtap="showMore">
        <image src="/images/icon/icon_chat_add.png"></image>
      </view>
      <view class="chat-btn mlr">
        发送
      </view>
  </div>

2.css

.flex {
  display: flex
}

.jcfs {
  justify-content: flex-start
}
.aifd {
  align-items: flex-end
}
.chat-input{height: auto;min-height: 40rpx;border-radius: 10rpx;background: #f6f6f6;width: 440rpx;padding: 15rpx 20rpx;}
.chat-input textarea{height: auto;min-height: 40rpx;line-height: 40rpx;font-size: 32rpx;max-height: 140rpx;width: 440rpx;}