css – 为什么webkit过滤器上的堆叠顺序更改悬停?

前端之家收集整理的这篇文章主要介绍了css – 为什么webkit过滤器上的堆叠顺序更改悬停?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在应用webkit过滤器时,我注意到堆叠顺序存在一个奇怪的问题.为什么当我将鼠标悬停在图像上时,堆叠顺序会发生变化?

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

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

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

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

这是我的HTML

  1. <ul>
  2. <li>
  3. <a href="#">
  4. <div class="slide-content">
  5. <div class="slide-title">
  6. <h1>hello world</h1>
  7. </div>
  8. <div class="slide-desc">
  9. <p>a description about something</p>
  10. </div>
  11. </div>
  12. <img src="http://img4.wikia.nocookie.net/__cb20130920142351/simpsons/images/e/e9/Pic_1187696292_8.jpg"/>
  13.  
  14. </a>
  15. </li>
  16. </ul>

CSS

  1. li {
  2. list-style:none;
  3. }
  4.  
  5. .slide-content {
  6. position:absolute;
  7. color:red;
  8. top:50px;
  9. }
  10.  
  11. li a:hover img{
  12. -webkit-filter: grayscale(100%); /* For Webkit browsers */
  13. }

解决方法

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

07002

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
.

该规范还指出:

07003

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

猜你在找的CSS相关文章