Html 更改文本区域的高度和宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24994395/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:22:02  来源:igfitidea点击:

Change the height and width of text area

htmlcssasp.nettwitter-bootstraptextarea

提问by John Jerrby

I need to change the width and the height of the <textarea>tag of HTML and I need it to have just two lines (rows). Currently, it has just one line. Any idea how to fix this?

我需要更改<textarea>HTML 标签的宽度和高度,我需要它只有两行(行)。目前,它只有一条线。知道如何解决这个问题吗?

For the width, even if I change it to 1000pxnothing changed and I don't understand why.

对于宽度,即使我将其更改为1000px没有更改,我也不明白为什么。

<div>
    <textarea rows="2" cols="200" disabled="disabled" style="width:500px; height: 10px;">
        Date
        User 
    </textarea>
</div>

I'm using Bootstrap in an MVC5 application.

我在 MVC5 应用程序中使用 Bootstrap。

回答by speak

Remove the height declaration on the textarea, just specify the rows using rows="2"

删除 上的高度声明textarea,只需使用指定行rows="2"

<textarea rows="2" cols="200" disabled="disabled" style="width:500px;">
Date
User 
</textarea>

heightwill conflict with rowsand widthwill conflict with cols.

height将与 发生冲突,rows并将与width发生冲突cols

回答by Youness

try doing this :

尝试这样做:

<textarea rows="2" cols="200" disabled="disabled" style="width:500px !important;height:250px !important;">
Date
User 
</textarea>

PS :replace height:250px by the height you want

PS:用你想要的高度替换 height:250px

回答by Hitesh Sahu

Keep reading if you want to set height of your text areas depending on size of the content

如果您想根据内容的大小设置文本区域的高度,请继续阅读

<textarea  id ="code" rows="2" cols="200" disabled="disabled" style="width:100%; height:auto"  >
    <!DOCTYPE html>
    <html>
    <body>

    <h1>My First Heading</h1>
    <p>My first paragraph.</p>

    </body>
    </html>

    </textarea>

And then in Document ready assign height of text area = scroll size

然后在文档准备好分配文本区域的高度 = 滚动大小

$(document).ready(function(){

  textAreaAdjust(document.getElementById('code') );
});

function textAreaAdjust(o) {
  o.style.height = "1px";
  o.style.height = (o.scrollHeight)+"px";
}