Html 调整 textArea 的高度和宽度以适应表格的 <td>

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

Adjust the textArea height and width to fit in <td> of a table

html

提问by user1275375

I am displaying the html content in a table. For printing the tags i am using textAreain the <td>of the table. So i want to adjust the height and width of textAreaso that it is equal to the <td>. How can i do this

我在表格中显示 html 内容。对于打印标签,我使用textArea<td>表格。所以我想调整 的高度和宽度textArea,使其等于<td>. 我怎样才能做到这一点

回答by Vladimir Starkov

dabblet.demo
enter image description here

dabblet.demo
在此处输入图片说明

the problem is that textarea behave not normal box-model, that's why we need this trick with box-sizing

问题是 textarea 的行为不是正常的 box-model,这就是为什么我们需要这个 box-sizing 的技巧

this CSSwill help you:

CSS将帮助您:

textarea {
    border: none;
    width: 100%;
    -webkit-box-sizing: border-box; /* <=iOS4, <= Android  2.3 */
       -moz-box-sizing: border-box; /* FF1+ */
            box-sizing: border-box; /* Chrome, IE8, Opera, Safari 5.1*/
}

if you have no access to cssfile, you can use inline css

如果您无法访问css文件,则可以使用内联 css

like this:

像这样:

<textarea style="border: none; width: 100%; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;"> </textarea>

回答by u?nb??s

Try using this CSS:

尝试使用这个 CSS:

td textarea {
    width: 100%;
    height: 100%
}

Or inline:

或内联:

<td>
    <textarea style="width: 100%; height: 100%; border: none">
    </textarea>
</td>

回答by KiiroSora09

give the textarea a 100% width and height style

给 textarea 一个 100% 宽度和高度的样式

td textarea {
 width:100%;
 height: 100%;
}

but also take into account the paddings and borders or the textarea so that it would not overflow from the td.

但也要考虑到填充和边框或 textarea,这样它就不会从 td 溢出。

hope this helps.

希望这可以帮助。