Weird :hover bug with z-index and img

By : Xavier
Source: Stackoverflow.com
Question!

I am having a very weird bug trying to highlight some parts of an image with overlays (higher z-index) on :hover. In Safari / Firefox / Chrome, no issue. But in IE (8 or 9), my simple CSS code doesn't work as it seem that IE doesn't trigger the :hover when the overlays are not always visible (no background-color or visibility:hidden)

Here is a MWE with the HTML and CSS:

<html>
<head>
  <style>
    .photo-notes {
      position: absolute;
      z-index: 998;
    }
    .photo-notes ul {
      position: relative;
    }
   .photo-notes li {
      list-style: none;
      position: absolute;
      background: #ccc;
      z-index: 999;
    }
    .photo-notes li:hover {
      background: red;
    }
    .photo-container {
      z-index: 1;
    }
  </style>
</head>
<body>
<div>
  <div class="photo-notes">
    <ul>
      <li style="left:  25px; top: 20px; width: 50px; height: 100px;"> </li>
    </ul>
  </div>
  <div class="photo-container">
    <img src="http://www.google.com/logos/2012/newyearsday-2012-hp.jpg"/>
  </div>
</div>
</body>
</html>

The code above works, but if you try to remove the background: #ccc or add visibility:hidden from/to the li styling, it stops working under IE (no more :hover effect).

The additional weird thing is that it does work (the :hover gets triggered) without background or with visibility:hidden on the li if the <img> line is removed. So it's not an issue of :hover not being possible on an element that's not visible in IE as one would think, and I've tried adding explicit z-indexes everywhere without success...

Any idea of what's happening and how to solve it?

By : Xavier


Answers

Well, I solved it myself by setting a background and opacity:0 on the li (which for IE means filter: alpha(opacity:0)). This way, the :hover gets triggered properly.

By : Xavier


This video can help you solving your question :)
By: admin