【问题标题】:How to make container div (of a given height) increase its height when the textarea inside it is resized?调整内部文本区域的大小时,如何使容器 div(具有给定高度)增加其高度?
【发布时间】:2022-01-22 02:42:10
【问题描述】:

这是我的代码。

div {
  background: orange;
  height: 200px;
  padding: 10px;
}
textarea {
  background: lightblue;
  border: 5px solid blue;
  width: 75%;
  height: 50%;
  resize: both;
}
<div>
  <textarea>foo</textarea>
</div>

当调整textarea 的大小以使其高度大于div 的高度时,它会溢出div。当textarea 被调整大小以增加其高度时,有没有办法使容器div 自动扩展以包围较大的textarea

【问题讨论】:

标签: css height


【解决方案1】:

height 更改为min-height 基本上意味着如果他有成长的理由-他会成长,但不会低于价值

你可以对宽度属性做同样的事情,或者将调整大小设置为垂直

div {
  background: orange;
  min-height: 200px;
  padding: 10px;
}
textarea {
  background: lightblue;
  border: 5px solid blue;
  width: 75%;
  height: 50%;
  resize: both;
}
<div>
  <textarea>foo</textarea>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-02
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多