【问题标题】:Z-index broken in IE8?IE8中的Z-index坏了?
【发布时间】:2009-08-17 20:20:23
【问题描述】:

此代码适用于我尝试过的所有其他浏览器,IE8 除外。

IE8 似乎忽略了 z-index - 并且弹出窗口变成了弹出窗口。

它在正确的位置,只是在缩略图下方呈现。

有人吗?

谢谢!

HTML:

<a class="thumbnail" href="#thumb">
    <img src="comic_a3_thumb.jpg" height="300" width="212" border="0"
         style="float:right; margin-top:10px;margin-bottom:10px;"
         alt="description" />
    <span>
        <img src="/images/comic_a3_popup.jpg" />
    </span>
</a>

CSS:

.thumbnail{
    position: relative;
    z-index: 0;
}

.thumbnail:hover{
    background-color: transparent;
    z-index: 50;
}

.thumbnail span{ /*CSS for enlarged image*/
    position: absolute;
    background-color: lightyellow;
    padding: 5px;
    left: 0px;
    border: 1px dashed gray;
    visibility: hidden;
    color: black;
    text-decoration: none;
}

.thumbnail span img{ /*CSS for enlarged image*/
    border-width: 0;
    padding: 2px;
}

.thumbnail:hover span{ /*CSS for enlarged image on hover*/
    visibility: visible;
    top: -140px; /*position where enlarged image should offset horizontally */
    left: -500px;
}

【问题讨论】:

    标签: internet-explorer-8 z-index


    【解决方案1】:

    简单的答案是将大于.thumbnail:hover 值的z-index 值添加到span 的悬停状态。

    .thumbnail:hover span{ /*CSS for enlarged image on hover*/
        visibility: visible;
        top: -140px; /*position where enlarged image should offset horizontally */
        left: -500px;
        z-index: 51;
    }
    

    【讨论】:

      【解决方案2】:

      将这些行放在您的页面标题中

      <!--[if IE]>
          <style>
                  #your_faulty_div{
                  background-color:#000; /*any color it doesn't matter*/
              filter: alpha(opacity=0);
              }
              </style>
      <![endif]-->
      

      your_faulty_div 是由于 IE z-index 错误而导致行为异常的 div。

      工作顺利,我在所有我放置元素重叠的项目中都使用它。

      【讨论】:

      • 行为不端是什么意思?是应该放在顶部的 div 还是应该放在后面的 div?给它一个不透明度为 0 会将它隐藏在一起吗?我自己也有类似的问题。谢谢!
      【解决方案3】:
      【解决方案4】:

      解决此问题的方法是向缩略图添加一个类,如下所示:

      .thumbnail:hover img.thumb {z-index:-50; position:relative;}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-08
        • 1970-01-01
        • 2014-05-02
        • 2015-02-20
        • 2012-03-31
        • 1970-01-01
        • 1970-01-01
        • 2011-11-04
        相关资源
        最近更新 更多