【问题标题】:How to remove bottom padding in textarea? [closed]如何删除textarea中的底部填充? [关闭]
【发布时间】: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>

【问题讨论】:

  • 没有填充,我看不到
  • 您使用的是哪个浏览器?
  • 你可能想看看这个stackoverflow.com/questions/995168/…
  • 可能是其他 css 造成的,您必须提供一个 live 版本或一个 fiddle 以便我们重现问题
  • textarea scrollheight 是在 高度变化使滚动条消失之前测量的......这使得 textarea 的内部宽度有点大......然后文本换行取那个滚动条的宽度,在底部留下一些空白。 @Farid 的解决方案是防止出现任何滚动条......所以在高度变化之前所做的测量是正确的。

标签: javascript jquery html css


【解决方案1】:

你应该使用

溢出-y:隐藏

如下

$('textarea').css("height", $("textarea").prop("scrollHeight"))
textarea {
  width: 300px;
  resize: none;
  margin: 0;
  padding: 0;
  overflow-y: hidden;
}
<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-23
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-12-29
    • 2012-09-02
    • 2018-04-01
    相关资源
    最近更新 更多