Question

I'm editing the CSS for the shadow DOM elements of an input[type=range], and I want to extend the slider thumb to cover the div below, and to do this, I have to set the position of the thumb as fixed. The problem is that in the div below that has to go below the thumb I have some divs that have position: relative (and cannot be positioned differently), which somehow put them in foreground, covering the thumb.

This is the code. However I made a jsFiddle to explain better my problem.

HTML

<input type="range" id="slider" />
<div id="container">
    <div id="left"></div>
    <div id="right">
        <div id="content"></div>
    </div>
</div>

CSS:

#slider {
    width: 400px;
    -webkit-appearance: none;
    background: red;
    height: 30px;
}

#slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 85px;
    background: black;
    position: fixed;
    top: 10px;
    left: 120px;
}

#container {
    width: 400px;
}

#left {
    width: 100px;
    height: 50px;
    background: blue;
    float: left;
}

#right {
    background: green;
    width: 300px;
    height: 50px;
}

#content {
    position: relative;
    width: 50px;
    height: 25px;
    background: yellow;
    left: 100px;
    top: 10px;
}

Basically, I want the black bar to cover the yellow div, without removing the position: relative property from that div. Is that possible?

Was it helpful?

Solution

You need to specify the z-index to change the natural stacking order of elements positioned anything other than static.

So I added a value of 1 for the z-index here:

#slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 85px;
    background: black;
    position: fixed;
    top: 10px;
    left: 120px;
    z-index: 1;
}

Forked your fiddle here.

OTHER TIPS

Setting the position to relative worked for me.

Starting css with problem

    input[type=range]::-webkit-slider-thumb {
  box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
  border: 0px solid #000000;
  height: 30px;
  width: 15px;
  border-radius: 0px;
  background: #004687;
  cursor: pointer;
  -webkit-appearance: none;
  margin-top: -0.2px;
  z-index:5;
}

Ending css:

        input[type=range]::-webkit-slider-thumb {
    box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
      border: 0px solid #000000;
      height: 30px;
      width: 15px;
      border-radius: 0px;
      background: #004687;
      cursor: pointer;
      -webkit-appearance: none;
      margin-top: -0.2px;
      z-index:5;

  position:relative;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top