【问题标题】:Extend range thumb over relative positioned div将范围拇指扩展到相对定位的 div
【发布时间】:2013-02-12 00:37:36
【问题描述】:

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

这是代码。不过我做了一个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,而不从该 div 中删除 position: relative 属性。这可能吗?

【问题讨论】:

  • 在定位的元素上使用 z 索引

标签: jquery css range css-position shadow-dom


【解决方案1】:

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

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

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

叉你的小提琴here

【讨论】:

  • 嗯。我发誓我试图给拇指一个 z-index,但它没有用。从那以后我一定改变了其他东西......无论如何,非常感谢你^_^
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    • 2012-08-17
    相关资源
    最近更新 更多