如何使用CSS自动增长文本区域? [英] How to autogrow a textarea with CSS?

查看:56
本文介绍了如何使用CSS自动增长文本区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个从小框开始的文本区域(单行),是否有可能使用CSS自动增长到多行,因为用户键入多行直到出现滚动条时显示的设置限制(300px).全部输入自动溢出?

Given a textarea that starts off as a small box, single line, is it possible using CSS to automatically grow to have multiple lines as the user types multiple lines up until say a set limit (300px) when a scrollbar would appear with overflow auto with all the inputs?

推荐答案

是的,您可以使用css3.您可能需要在浏览器前添加前缀.

Yes you can with css3. You may need to prefix these with the browser.

textarea { 
    resize: both; 
} /* none|horizontal|vertical|both */
textarea.vert { 
    resize: vertical; 
}
textarea.noResize { 
    resize: none; 
}

然后您可以使用以下方法将它们限制为最大高度和宽度:

You can then restrain them to max heights and widths using:

textarea { 
    resize: vertical; 
    max-height: 300px; 
    min-height: 200px; 
}
textarea.horiz { 
    resize: horizontal; 
    max-width: 400px; 
    min-width: 200px;
}

我从过去引用的帖子中删除了这些内容:

I've pulled these from a post I've referenced in the past:

> 使用CSS自定义Textarea大小调整

这篇关于如何使用CSS自动增长文本区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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