Padding top not working on scrolling textarea
Asked Answered
A

2

12

I am trying to maintain top padding on textarea. But when scrollbar appears, padding top is not working. enter image description hereenter image description here

Here is my html and css. Can anyone please help me out? Thank you.

<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;
}
Aggression answered 31/5, 2017 at 9:38 Comment(3)
This should work. https://mcmap.net/q/1010348/-webkit-textarea-losing-top-amp-bottom-padding-on-vertical-scrollbarExercise
This worked for me. Thank you. @ExerciseAggression
Does this answer your question? -webkit- textarea losing top & bottom padding on vertical scrollbarCampground
C
8

You can use a top border in place of padding to prevent the content of the textarea from reaching behind the label. Then, you can reconstruct the borders of the textarea using a box-shadow.

This solution preserves the resizing both vertically and horizontally.

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;
}
<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>
Colloquy answered 29/6, 2022 at 23:20 Comment(0)
B
4

This solves your issue. The only caveat is you must set a width and the textarea will only be able to expand vertically.

Essentially, you'll add class 'outer' to the form-group div and fake that as the entire textarea. <textarea> by itself will not constrain itself to border padding/margin.

.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;
}
<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>
Bradleybradly answered 31/5, 2017 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.