CSS 如何让 textarea 填充 div 块?

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

How to make textarea to fill div block?

csstextareawidth

提问by Rihards

Check out how far have I got it here: [link was removed] How can I make the textarea above the green button to fill the div block? I mean, how to make the textarea exactly the same width as the comment block?

看看我在这里得到了多远:[链接已删除]如何使文本区域位于绿色按钮上方以填充 div 块?我的意思是,如何使 textarea 与注释块的宽度完全相同?

回答by acpmasquerade

Please refer to this article which implements the CSS3 box-sizing property http://css-tricks.com/box-sizing/

请参考这篇实现 CSS3 box-sizing 属性的文章 http://css-tricks.com/box-sizing/

A quick solution for this is to set

对此的快速解决方案是设置

textarea {
     width: 100%;
     -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
     -moz-box-sizing: border-box;    /* Firefox, other Gecko */
     box-sizing: border-box;         /* Opera/IE 8+ */
}

And here is a working example which implements the box-sizing property http://css-tricks.com/examples/BoxSizing/

这是一个实现 box-sizing 属性的工作示例 http://css-tricks.com/examples/BoxSizing/

Using widths like 99% or somewhat lesser to adjust within the container div, has already been discouraged.

已经不鼓励使用 99% 或稍小一些的宽度在容器 div 内进行调整。

回答by Vinz

Dimensioning textareas in percents has somehow never worked properly, I had the same problem years ago and ended up using width: 99%....

以百分比为单位对 textareas 进行尺寸标注一直无法正常工作,几年前我遇到了同样的问题,最终使用了 width: 99% ....

I suggest you use a divaround the textarea to draw the rounded border and remove the border on the textarea itself. This way the width of the textarea doesn't need to be exact, you could use 98% or 99%.

我建议您div在 textarea 周围使用 a绘制圆形边框并删除 textarea 本身的边框。这样 textarea 的宽度不需要精确,你可以使用 98% 或 99%。