Putting a scrollbar outside padded region
css, html
Solution
This fiddle might be, what you want: Fiddle
This example contains gradients for the top and bottom parts but can be solid colors of course, if you want that.
You can play around with the padding of the `#content` Element, but note, that you need an additional element to the right, if you want to create a passepartout-effect.
#container{
position:relative;
height:300px;
width:300px;
}
#content{
height:200px;
width: 200px;
padding: 50px;
overflow-y: auto;
background-color: #cef;
}
.bar {
position:absolute;
width: 280px;
height: 50px;
background-color:#bcd;
}
.vbar {
position:absolute;
width: 50px;
height: 280px;
background-color:#bcd;
}
#topbar{
top:0;
}
#bottombar{
bottom:0;
}
#leftbar{
top:0;
}
#rightbar{
right:20px;
top:0;
}
<div id="container">
<div id="topbar" class="bar"> </div>
<div id="content" class="pad">
1<br> 2<br> 3<br> 4<br> 5<br> 6<br> 7<br> 8<br> 9<br> 10<br> 11<br> 12<br> 13<br> 14<br> 15<br> 16<br> 17<br> 18<br> 19<br> 20<br> 21<br> 22<br> 23<br> 24<br> 25<br> 26<br> 27<br> 28<br> 29<br> 30<br> 31<br> 32<br> 33<br> 34<br> 35<br> 36<br> 37<br> 38<br> 39<br> 40<br> 41<br> 42<br>
</div>
<div id="bottombar" class="bar"></div>
</div>
edit: changed the fiddle link, the old link with the gradients is the following: Fiddle
Problem
How can I place a vertical scrollbar while keeping padding in all directions at all times in the content area? The picture below better describes what I am looking for. I only have the obvious "padding: x" to show for my work :( I tried nesting padding and it was hilarious :) I would like to avoid JavaScript unless it is really needed.