开发者

opacity in ie using absolutely positioned divs not working

I've been banging my head against the wall for a few hours how trying to sort this out. I'm trying to position one div on top of another for the purpose of fading one in on top of the other. The divs will have an image and some other html in them. I cannot get opacity to work in ie8. I've simplified my html as much as possible:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<style>

  * { margin: 0; padding: 0; }

  .carousel-container {
    position: relative;
  }  

  .carousel-overlay {
    position: absolute;
  }

  #carousel-container-a {
    opacity: 1; 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
    filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
  }

  #carousel-container-b {
    opacity: 0; 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
    filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);    
  }

  h1 { font-size: 100px; }


</style>

</head>
<body>


<div id="carousel-container-a" class="carousel-container">
  <div class="carousel-overlay" style="left: 10px; top: 10px;">
    <h1 style="color: black;">Showcase</h1>
  </div>
  <!-- other elements removed for simplicity -->
</div>
<div  id="carousel-container-b" class="carousel-container">
  <div class="carousel-overlay" style="left: 20px; top: 20px;">
    <h1 style="color: red;">Welcome</h1>
  </div&开发者_运维百科gt;
  <!-- other elements removed for simplicity -->
</div>


</body>
</html>

Why doesn't the opacity work? How can I make it work?


Give this a shot:

-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
opacity: 0;

This incorporates both statements for IE7 and IE8. This should handle the opacity correctly for you. While this is similar to what you are already using, I rearranged the statements. According to Microsoft, you have to list the new extension format first, and then older settings. This in addition to the CSS opacity setting.


Try applying haslayout to the elements.

#carousel-container a { zoom:1; }

Width/height/inline-block and a slew of others will work as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜