How to make a sticky slider remain functional as page scrolls

I have a slider at the top of my page. This slider allows user to change date range for data which then triggers updates to graphs.

Since there are so many graphs, it made sense to allow slider to move with page scroll so user does not have to go all the way back to the top to change dates with slider.

So I made the slider have position: sticky .

Problem: when slider scrolls over other HTML elements, it becomes “invisible” to mouse input. So if there is another HTML element under it, and I try to click on slider, the mouse selects the HTML element under it instead.

position: sticky is newer so there are not a lot of questions about this online and especially not for elements that have to be dynamic like a slider.

I found these:

  1. How can I make a div stick to the top of the screen once it’s been scrolled to?

But none of them answered my question completely. I did try updating the z-index with various values ranging from negative to positive but none worked.


<div class="container">
      <div id="selections" class="row">
        <p id="loading"></p>
        <div class="col-md-12">
          <div id="slider"></div>
            ><span id="dateLabel1"></span><span id="dateLabel2"></span
<!-- more divs -->


#selections {
  position: sticky;
  top: 0;
  background-color: #b2df8a;

Expected: as slider moves down with page scrolls, user should be able to continue to change slider values (and thereby update graphs).

Actual: as slider moves down, user unable to change slider values UNLESS there is no other HTML element overlapping with slider.

[I did [post]( this question in StackOverflow - in case it looks familiar to anyone - only because FCC site was down. No responses there so far but if you want to get points or reputation or badges, you can post your answer there].

Give #selections a positive z-index.

1 Like

Thanks @lasjorg. That worked! (But also, I’m sure I tried that…clearly I must not have saved or something equally dumb…frustrating). Thanks again!