I want to make a horizontal bar with a div and some css, so when I scroll down the webpage, the bar changes colors from left to right depending on how far the user scrolled the page.
The bar should be fixed, such that it stays always on top of the page. However, when I select "position: fixed", the elements disappear behind the bar. On the other hand, when I select "position: static", the bar disappears, when I scroll down.
Is it possible to have the bar always on top of the viewport AND such that no elements can disappear behind it?
EDIT
So far I've come up with this solution: I created a second div with the same width and height but with "position: static" and "z-index: -1".
This second div makes sure, that the bar and the elements don't overlap.
I think it's an ugly solution, but unfortunately the other suggestions didn't work so far.
Before:
After:
HTML:
<div class="loading_bar_horizontal_base"></div>
<div class="loading_bar_horizontal_base_static"></div>
CSS:
.loading_bar_horizontal_base {
position: fixed;
width: 100%;
height: 5px;
background-color: #ffe086;
}
.loading_bar_horizontal_base_static {
position: static;
width: 100%;
height: 5px;
z-index: -1;
}