简体   繁体   English

使textarea高度扩展到容器div的高度(在调整大小时)

[英]make textarea height expand to container div's height (on resize)

Is there a way to make these two textareas that are floated next to one another always be the same height. 有没有办法让这两个彼此浮动的textareas总是相同的高度。 The height of their container, which expands when one of them is resized. 容器的高度,当其中一个容器的大小调整时,它会扩展。 I've tried putting them in a container div and setting their height to 100%. 我已经尝试将它们放入容器div并将它们的高度设置为100%。 I've tried making a jquery function to resize them (you can see it commented out in the fiddle) which failed. 我已经尝试制作一个jquery函数来调整它们的大小(你可以看到它在小提琴中注释掉了)失败了。

http://jsbin.com/IkESUli/6/edit http://jsbin.com/IkESUli/6/edit

How can I make them always the same height after a resize? 如何在调整大小后使它们始终保持相同的高度?

textarea{
  min-height:150px;
  float:left;
  display:inline-block;
  overflow:auto;
}
#t2{
  width:30px;
  overflow:hidden;
  text-align: right;
  white-space:nowrap;
}

div.container{
  min-height:150px;
  border:1px solid black;
  display:inline-block;
}

This will works: 这将有效:

$(".t").mouseup(function(){
    $(".t").not($(this)).css("height", parseInt($(this).css("height"),10));
});

You could use mousemove instead of mouseup for "real time" effect. 您可以使用mousemove而不是mouseup来实现“实时”效果。

try setting textarea's height to 100% and container's height to 150px. 尝试将textarea的高度设置为100%,将容器的高度设置为150px。 when textarea is in 100% it will automatically fits into your parent div's height, hope this helps. 当textarea在100%时,它将自动适合你父级的高度,希望这会有所帮助。

textarea {      
    height: 100%;
    width: 100%;
    display: block;
}

div.container{ height: 150px; div.container {height:150px; min-height:150px; 最小高度:150像素; border:1px solid black; 边框:1px纯黑色; display:inline-block; 显示:内联块; } }

You can use javascript to implement the following scenario. 您可以使用javascript来实现以下方案。 Once the parent element changes its dimentions, for instance, height, you call the functios (ES6 Javascript version): 一旦父元素改变其尺寸,例如,高度,你调用functios(ES6 Javascript版本):

const makeDimensionsEqual = (someTextareaSelector, someParentElementSelector) => {

  document.querySelectorAll(someTextareaSelector)[0].style.height = 
    document.querySelectorAll(someParentElementSelector)[0]
    .getBoundingClientRect().height + "px"

}

const someTextareaSelector = '...' 
const someParentElementSelector = '...'
makeDimensionsEqual(someTextareaSelector, someParentElementSelector)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM