填充顶部不适用于滚动文本区域

Vai*_*ani 5 html css textarea

我试图在 textarea 上保持顶部填充。但是当滚动条出现时,padding top 不起作用。在此处输入图片说明在此处输入图片说明

这是我的 html 和 css。任何人都可以帮我吗?谢谢你。

<div class="form-group has-feedback issue-detail-text-area marginTop30">
       <textarea id="abc" name="abc" class="form-control clearable textArea x form-control-focus" rows="3" maxlength="500"></textarea>
       <span class="input-lable input-lable-focus">Other issue details (optional)</span>
</div>

#abc {
   padding-top: 22px;
   padding-bottom: 8px;
}
.marginTop30 {
   margin-top: 30px;
}
.input-lable-focus {
   top: 10px;
   font-size: 11px;
   opacity: 1;
   z-index: 100;
}
.input-lable {
   position: absolute;
   color: #b8bdc4;
   left: 18px;
}
Run Code Online (Sandbox Code Playgroud)

Pur*_*ten 6

您可以使用顶部边框代替填充,以防止文本区域的内容到达标签后面。然后,您可以使用框阴影重建文本区域的边框。

该解决方案保留了垂直和水平方向的大小调整。

label {
  font-size: 16px;
  line-height: 16px;
  font-weight: bold;
  
  /* Special styles here */
  position: absolute;
  padding: 8px 8px 8px;
}

textarea {
  border-radius: 4px;
  padding: 0 8px 8px;
  
  /* Special styles here */
  border: 0;
  border-top: 32px solid white;
  box-shadow: 0 0 0 1px #666;
}
Run Code Online (Sandbox Code Playgroud)
<label for="dog">A very important label</label>
<textarea name="dog" id="dog" cols="50" rows="10">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</textarea>
Run Code Online (Sandbox Code Playgroud)


小智 4

这解决了你的问题。唯一需要注意的是,您必须设置宽度,并且文本区域只能垂直扩展。

本质上,您将向表单组 div 添加“outer”类,并将其伪造为整个文本区域。<textarea>其本身不会将其自身限制为边框填充/边距。

.input-lable-focus {
  font-size: 11px;
  opacity: 1;
  z-index: 100;
}
.input-lable {
  color: #b8bdc4;
}
textarea {
  border: none;
  outline: none;
  width: 495px;
  max-width: 495px;
}
.outer {
  overflow: auto;
  padding: 10px 0 0 10px;
  width: 500px;
  border: 1px solid #aaa;
}
Run Code Online (Sandbox Code Playgroud)
<div class="form-group has-feedback issue-detail-text-area outer">
  <span class="input-lable input-lable-focus">Other issue details (optional)</span>
  <textarea id="abc" name="abc" class="form-control clearable textArea x form-control-focus" rows="3" maxlength="500"></textarea>
</div>
Run Code Online (Sandbox Code Playgroud)