html - 使用负 z-index 时灰度效果不起作用

标签 html css z-index grayscale

我创建了这个 jsbin 网页来向您展示我试图解释的内容。效果只是
使用正 z-index 时很好,但是如果我将 #flower id 的 z-index
更改为 -2 并将 #front id 更改为 -1 它不再起作用......我不知道为什么有时候是这样的。任何解释
将不胜感激。

http://jsbin.com/xexusaci/1/edit

#flower{
          position:relative;
          top:-600px;
          left:50px;
          z-index:1;
        }

      #front {
          z-index:2;
          position:relative;
          top:100px;
          height:600px;
          width:100%;
          background-color:lightblue;   
        }

       #flower{
          filter: url("data:image/svg+xml;utf8,<svg     xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='matrix' values='0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0'/></filter></svg>#grayscalerayscale");
          filter: gray;
          -webkit-filter: grayscale(100%);
          -moz-transition: all 0.5s ease-in-out;
          -webkit-transition: all 0.5s ease-in-out;
          transition: all 0.5s ease-in-out;
        }

        #flower:hover {
           filter: none;
           -webkit-filter: grayscale(0%);
        }

最佳答案

与 z-indices 无关,但您的 SVG ID 与 URL anchor 不匹配,因此它必须在 Gecko 中被破坏。

url("data:...filter id='grayscale'...#grayscalerayscale")

除此之外,无法在 Fx 28 或 Chrome 33 中重现所描述的错误。

关于html - 使用负 z-index 时灰度效果不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22940481/

相关文章:

javascript - 有人可以帮助我使用带有动态元素的 CSS/jQuery 固定 header 吗?

css - 如何创建Airbnb 主页模板?

javascript - 未定义的处理程序?

url - 打破巨大的 URL,这样它们就不会溢出

javascript - react 响应轮播 : How to display portrait orientation images while preserving aspect ratio and minimizing cropping?

html - 在 Internet Explorer 7 中使用 z-Index 定位 div

CSS 使用 z-index

DIV 中的 CSS 位置困境

javascript - 设置选择元素的选定值

html - 正确获取 img 内容的正确方法?