3

I have a textarea element with fixed width & height and no resize and when the vertical scrollbar appears the padding (top & bottom) of the element is ignored.

Here is a plnkr demo: http://plnkr.co/edit/jOeYXqkOZk3FCT24BRrk?p=preview
This happens only with Chrome (tested on Chromium, Linux version).

Here is my styling for the textarea element:

textarea{
    background-color: #1c1b1b;
    border-bottom: 3px solid #343434;
    border-radius: 4px;
    color: #fff;
    display: block;
    height: 165px;
    margin-bottom: 21px;
    padding: 10px;
    resize: none;
    width: 90%;
}

*One solution would be to wrap the textarea element inside a div with that specific padding, but then the scrollbar will not overlap that padding and will look kinda strange.
Edit: ok, maybe it won't look as strange as I thought, but I just wonder if there is a more elegant fix, within css maybe.

Tanase Butcaru
  • 962
  • 1
  • 10
  • 23
  • what do you mean `the scrollbar will not overlap that padding and will look kinda strange`? – jmore009 Jan 17 '15 at 18:08
  • @jmore009 the wrapper will have the padding and textarea will have none, so when the scrollbar (of the textarea element) will appear it won't start from the top of the div. – Tanase Butcaru Jan 17 '15 at 18:10
  • this might help you http://stackoverflow.com/questions/8895332/how-to-properly-style-a-text-area-with-inner-shadows-and-scrollbar – Vitorino fernandes Jan 17 '15 at 18:17
  • @VitorinoFernandes thx, but that doesn't help much. Actually, same happens with the accepted answer (check jsfiddle demo) and also on firefox - the top-bottom padding is ignored when vertical scrollbar appears. – Tanase Butcaru Jan 17 '15 at 18:21

1 Answers1

4

I've tried to think of a workaround, depending on your own hint. You've got it right, but didn't implement it yet. :) I just coded your idea. What I did was to enclose within a wrapper, and setting before and after pseudo elements to just hide the top and bottom parts. I hope that would solve your issue.

It would also run perfectly in Chrome, Firefox as well as in IE.

.container {
    width: 90%;
    position: relative;
}
textarea {
 background-color: #1c1b1b;
 border:0;
    border-radius: 4px;
    color: #fff;
    display: block;
    height: 165px;
    margin-bottom: 21px;
    padding: 10px;
    resize: none;
    width: 100%;
 border-radius: 4px;
}
.container:before, .container:after {
 content:'';
    display: block;
    height: 10px;
    background: #1c1b1b;
    position: absolute;
    left: 4px;
    right: 18px;
}
.container:before {
    top: 0px;
}
.container:after {
    bottom: 0px;
}
<div class="container">
    <textarea>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</textarea>
</div>
Chique
  • 735
  • 3
  • 15
  • This one works like I need! Thanks :) So, I guess this is a -webkit- issue with textarea scrollbar & padding property.. – Tanase Butcaru Jan 17 '15 at 18:52
  • 2
    Thats right @TanaseButcaru. Its not basically an issue, but its how Chrome perceives padding, vs how Firefox does. Personally, we all like the Firefox's one :). To chrome, padding is in absolute top and bottom positions, but in Firefox, they are like fixed, regardless of scroll. – Chique Jan 17 '15 at 18:58
  • Not working, there is cut piece in top right corner... – Lukáš Smida Nov 19 '21 at 14:22