【发布时间】:2018-02-04 00:44:25
【问题描述】:
如何去除textarea 中的底部填充?
$('textarea').css("height", $("textarea").prop("scrollHeight"))
textarea {
width: 300px;
resize: none;
margin: 0;
padding: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a </textarea>
【问题讨论】:
-
没有填充,我看不到
-
您使用的是哪个浏览器?
-
可能是其他 css 造成的,您必须提供一个 live 版本或一个 fiddle 以便我们重现问题
-
textarea
scrollheight是在 高度变化使滚动条消失之前测量的......这使得 textarea 的内部宽度有点大......然后文本换行取那个滚动条的宽度,在底部留下一些空白。 @Farid 的解决方案是防止出现任何滚动条......所以在高度变化之前所做的测量是正确的。
标签: javascript jquery html css