文本区域的 Bootstrap 5 浮动标签与滚动输入重叠

问题描述

查看 textarea 的浮动标签 https://getbootstrap.com/docs/5.0/forms/floating-labels/ 的文档,如果内容可滚动,则标签似乎与输入重叠:

Textarea label overlap

有没有办法防止这种情况发生并使标签下方的可滚动区域?

解决方法

这是 Bootstrap 5 #32800 的一个已知问题。

我所做的是一个小黑客,同时他们已经修复了这个错误。

基本上我在 textarea 之间创建了一个伪元素,并用白色背景色标记了一个图层。

.form-floating {
  position: relative;
  max-width: 300px; /* not relevant */
  margin: 40px 20px; /* not relevant */
}

.form-floating:before {
  content: '';
  position: absolute;
  top: 1px; /* border-width (default by BS) */
  left: 1px; /* border-width (default by BS) */
  width: calc(100% - 14px); /* to show scrollbar */
  height: 32px;
  border-radius: 4px; /* (default by BS) */
  background-color: #ffffff;
}

.form-floating textarea.form-control {
  padding-top: 32px; /* height of pseudo element */
  min-height: 80px; /* not relevant */
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">

<div class="form-floating fix-floating-label">
    <textarea class="form-control" placeholder="Leave a comment here" id="floatingTextarea"></textarea>
  <label for="floatingTextarea">Comments</label>
</div>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...