【发布时间】:2016-02-29 01:55:47
【问题描述】:
我有一个包含文本区域的 div。这个 div 有一个边框:1px 纯黑色。现在,当用户输入 textarea 时,textarea 会增长。
我有这个代码 -
$('#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')))
});
现在外部 div(文本区域外部)随之增长。但是这种高度的变化并没有反映在边框上。边界留在那里。如果可能的话,我怎样才能做到这一点。
PS - 当我在我的 Chrome (Ctrl+Shift+I) 中看到它时,我的外部潜水高度增加了,但边框没有反映这种变化。
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;}
【问题讨论】:
-
您能否展示 HTML 或包含示例(例如来自 JSFiddle)?这样会更容易回答。
-
请把 HTML 和 CSS 代码放在这里