1

我正在为 的阴影 DOM 元素编辑 CSS input[type=range],并且我想扩展滑块拇指以覆盖下面的 div,为此,我必须将position拇指设置为fixed。问题是,在下面必须位于拇指下方的 div 中,我有一些 div 具有position: relative(并且不能以不同的方式定位),它们以某种方式将它们放在前景中,覆盖拇指。

这是代码。但是我做了一个jsFiddle来更好地解释我的问题。

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;
}

基本上,我希望黑条覆盖黄色 div,而不position: relative从该 div 中删除属性。那可能吗?

4

2 回答 2

1

您需要指定z-index以更改除 之外的任何元素的自然堆叠顺序static

所以我在这里添加了一个值 1 z-index

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

在这里叉你的小提琴。

于 2013-02-26T14:21:43.500 回答
0

将位置设置为相对对我有用。

启动有问题的 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;
}

结束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;
}
于 2015-04-30T19:51:06.083 回答