Within a div, there is a textarea that grows in size as the user types. The div itself has a border of 1px solid black. However, when the textarea expands, the outer div also increases in height, but the border does not adjust accordingly. How can this be resolved?
The following code is used for this functionality:
$('#sendtext').on('input', function(){
$this = $(this);
var totalHeight = $this.prop('scrollHeight') - parseInt($this.css('padding-top')) - parseInt($this.css('padding-bottom'));
$this.height(totalHeight);
$div = $('#sendmsg');
$div.height($div.prop('scrollHeight') - parseInt($div.css('padding-top')) - parseInt($div.css('padding-bottom'))
});
Even though the outer div's height changes are visible in Chrome developer tools, the border remains unaffected. See image here.
HTML -
<div id="sendmsg">
<textarea id="sendtext" value="">
</textarea>
<div class="clearBoth"></div>
</div>
CSS -
#sendmsg{width:100%; height:auto;}
#sendtext{width:95%; margin:10px; padding:5px; transition: width 0.25s; resize:none; overflow:hidden;}
.clearBoth{clear:both;}