I want to add a faded section to the top of my DIV such that, when a user scrolls, the content gradually fades out. I have set up some CSS that achieves this but has one issue.. The faded section scrolls with the content rather than staying fixed in place.
How can I fix this? Do I need help from jQuery or is it possible using CSS and will this work in anything bar CSS3 compatible browsers? (I know I dont have correct vendor prefixes on my linear-gradient
s yet)
Here is my code so far and a fiddle:
.fadedScroller {
overflow: auto;
position: relative;
height: 100px;
}
.fadedScroller:after {
content: '';
top: 0;
left: 0;
height: 20px;
right: 0;
background: linear-gradient(to bottom, rgba(251,251,251,1) 0%,rgba(251,251,251,0) 100%);
position: absolute;
}
Update
I have updated my fiddle to point out that using position: fixed
doesnt actually work as the faded section then appears above the containing div not fixed to the top.