Html 文本区域自动高度 CSS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25518182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Textarea Autoheight CSS
提问by FLAdmin
I have a textarea that will hold data from a database. It will be disabled so that the user cannot interact with it.
我有一个 textarea 将保存来自数据库的数据。它将被禁用,以便用户无法与其交互。
Is there a way to set the height via css so that it fits the area. IE: if there is only one line of text, the textarea height is only 1 row or if there is 3 lines of text, the textarea height is 3 rows?
有没有办法通过 css 设置高度,使其适合该区域。IE:如果只有一行文本,textarea 高度只有1 行,或者如果有3 行文本,textarea 高度是3 行?
It's part of an MVC application if that helps at all. I'm using the html.textareafor as well.
如果有帮助的话,它就是 MVC 应用程序的一部分。我也在使用 html.textareafor 。
回答by Jatin
Simplest I can think of is this:
我能想到的最简单的是:
div {
display:inline-block;
border: solid 1px #000;
min-height:10px;
width: 300px;
}
More Options:
更多选择: