我可以使文本区域与文本一起增长到最大高度吗? [英] Can I make a textarea grow with text to a max height?

查看:106
本文介绍了我可以使文本区域与文本一起增长到最大高度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我的div中的数据可以是各种大小.当用户单击div之一时,它需要变成一个可编辑的文本区域.宽度是恒定的,但是我希望高度以原始div的高度开始,然后增加到最大高度,然后再添加滚动条.有可能吗?

I'm working on a project where I have data in divs that can be various sizes. When a user clicks on one of the divs, it needs to turn into an editable textarea. The width is constant, but I'd like the height to start as the height of the original div and then grow to a max height before adding a scrollbar. Is that possible?

推荐答案

您可以使用contenteditable并让用户直接输入div,这是一个演示:

You can use contenteditable and let the user input in a straight div, here's a demo: http://jsfiddle.net/gD5jy/

<div contenteditable>
    type here...
</div>

CSS

div[contenteditable]{
    border: 1px solid black;
    max-height: 200px;
    overflow: auto;
}

这篇关于我可以使文本区域与文本一起增长到最大高度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆