You can do this using the :before
or :after
css selector on the parent div/container:
Option 1:
body {
margin: unset;
}
.container {
border: 3px solid black;
width: 500px;
height: 100px;
padding: 0;
margin: 0 auto;
position: absolute;
top: 50%;
left: 50%;
font-size: 30px;
font-family: calibri;
overflow-y: auto;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.container:before {
content: '';
position: absolute;
bottom: 0;
background: linear-gradient(to bottom, transparent, white);
height: 50%;
width: 100%;
}
<div class="container">
<div>item1 - test</div>
<div>item2 - test</div>
<div>item3 - test</div>
<div>item4 - test</div>
<div>item5 - test</div>
</div>
https://codepen.io/anon/pen/KYRvqz
Option 2: (works with scrolling)
body {
margin: unset;
}
.containerwrapper {
border: 3px solid black;
width: 500px;
height: 100px;
padding: 0;
margin: 0 auto;
position: absolute;
top: 50%;
left: 50%;
overflow-y: auto;
font-size: 30px;
font-family: calibri;
overflow: hidden;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.containerwrapper:before {
content: '';
position: absolute;
bottom: 0;
background: linear-gradient(to bottom, transparent, white);
height: 100%;
width: 100%;
pointer-events: none;
}
.container {
width: 100%;
height: 100%;
overflow-y: scroll;
}
<div class="containerwrapper">
<div class="container">
<div>item1 - test</div>
<div>item2 - test</div>
<div>item3 - test</div>
<div>item4 - test</div>
<div>item5 - test</div>
</div>
</div>
What I've done here is, I've made two wrappers for the text and I gave the .contentwrapper, pointer-events: none;
so that you can scroll, click, hover, etc through the .contentwrapper.
This will give the fading effect to the scrollbar as well, to fix that just change this:
.containerwrapper:before {
width: 100%;
}
to:
.containerwrapper:before {
width: calc(100% - 17px); // 17px is the width for the default scrollbar
}
https://codepen.io/anon/pen/gyzGGM?editors=1100
Option 3 (works without absolute positioning):
See kmoser's answer.
Hope this helps!