css - 为什么 webkit 过滤器悬停时堆叠顺序会发生变化?

标签 css filter webkit z-index

我注意到在应用 webkit 过滤器时我的堆叠顺序有一个奇怪的问题。为什么,当我将鼠标悬停在图像上时,堆叠顺序会发生变化?

我宁愿不必使用 z-indexing 来解决这个问题,因为它会破坏其他网站元素。

这是我的 JSFiddle http://jsfiddle.net/r13ycy1p/

请原谅荷马,我只需要一张图片。

编辑:如何反转效果以阻止绝对位置 div 被隐藏?

这是我的 HTML

<ul>
<li>
    <a href="#">
        <div class="slide-content">
            <div class="slide-title">
                <h1>hello world</h1>
            </div>
            <div class="slide-desc">
                <p>a description about something</p>
            </div>
        </div>
        <img src="http://img4.wikia.nocookie.net/__cb20130920142351/simpsons/images/e/e9/Pic_1187696292_8.jpg"/>

    </a>
</li>
</ul>

CSS

li {
list-style:none;    
}

.slide-content {
position:absolute;
color:red;
top:50px;
}

li a:hover img{
-webkit-filter: grayscale(100%); /* For Webkit browsers */
}

最佳答案

这是因为 none 以外的值建立了一个 stacking context .这记录在 spec(目前处于工作草案状态):

2 Module interactions

This specification defines a set of CSS properties that affect the visual rendering of elements to which those properties are applied; these effects are applied after elements have been sized and positioned according to the Visual formatting model from [CSS21]. Some values of these properties result in the creation of a containing block, and/or the creation of a stacking context.

规范还指出:

5 Graphic filters: the filter property

A computed value of other than none results in the creation of a stacking context [CSS21] the same way that CSS opacity does.

关于css - 为什么 webkit 过滤器悬停时堆叠顺序会发生变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25764404/

相关文章:

HTML5 Web SQL 不断重复并破坏旧数据库

swift - 如何在 Swift 3 中使用 WebKit .click() 按钮?

html - 添加了第二个 css 下拉列表,它不会排队

html - 如何使用 CSS 过渡将 div 从屏幕外滑入绝对布局?

Android:使用正则表达式按标签过滤 Logcat

ios - 按属性的第一个字母过滤

html - CSS - 使用转换在标题下居中 div 时遇到问题

css - 当我减小浏览器宽度时,如何确保我的标题不会改变?

java - 使用谷歌 Collection 过滤和排序列表

webkit - 如何减少phantomjs内存消耗?