简体   繁体   English

z-index在Chrome中不起作用,在FF,IE等中均可工作

[英]z-index not working in Chrome, works in FF, IE etc

I have a div with an image that when clicked shows a larger image with a higher z-index this displays outside the div of the smaller image. 我有一个div图像,当单击该图像时会显示具有较高z索引的较大图像,该图像显示在较小图像的div之外。 In FF, IE, etc it displays correctly but in Chrome it shows the overlayed image but it is hidden within the containing div "Overflow: hidden", (it should show outside the box its wider than the containing box and a higher z-index). 在FF,IE等中,它可以正确显示,但在Chrome中,它可以显示覆盖的图像,但隐藏在包含div的“溢出:隐藏”中((应在框外显示其宽度大于包含框,并显示较高的z-index) )。

So in essence clicking on the underlying image one column wide loads the bigger wider image 2 columns wide on top and outside the div of the underlying image. 因此,从本质上来说,单击基础图像一栏宽将在基础图像的div顶部和外部加载较大的较宽图像2列宽。

The code below works as I mentioned in IE, FF etc 下面的代码按我在IE,FF等中提到的方式工作

Here is the HTML: 这是HTML:

<div id="wrapper">
    <div id="list">
        <div class="item">
            <div class="tile bg0 hoverImage0">
                <img src="images/expand-icon.png" class="mouse" alt="Image is clickable" title="Image is clickable">
                <img src="images/Image_Expandible.jpg" alt="W">
            </div>
            <div class="tile imageExpanded overlayImage0" style="visibility:hidden">
                <img src="images/Image_EXPANDED.jpg" alt="W">
            </div>
        </div>
    </div>
</div>
</div>

THE CSS: CSS:

#wrapper {
    max-width: 80em;
    min-height: 66em;
    margin: 0 auto;
    position: relative;
    z-index: 1000;
}
#list {
    width: 100%;
    overflow: hidden;
    margin-bottom: .875em;
    -webkit-column-count: 3;
    -webkit-column-gap: 1em;
    -webkit-column-fill: auto;
    -moz-column-count: 3;
    -moz-column-gap: 1em;
    -moz-column-fill: auto;
    column-count: 3;
    column-gap: 1em;
    column-fill: auto;
    position: relative;
    z-index: 1000;
}
.item {
    margin-bottom: 1em;
    -webkit-column-break-inside: avoid;
    -moz-column-break-inside: avoid;
    column-break-inside: avoid;
    border: 0px solid #000;
    overflow: visible;
    position: relative;
    z-index: 1000;
}
.tile {
    border: 2px solid #908094;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    z-index: 2000;
}
.mouse {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 2000;
}
.hoverImage0 {
    position: relative;
    z-index: 2000;
}
.overlayImage0 {
    width: 1200px;
    height: 840px;
    position: absolute;
    top: 0;
    left: 0;
    transition:all 50ms ease-in-out 50ms;
    background: #000;
    overflow: visible;
    z-index: 5000;
}
.imageExpanded {
    width: 848px;
    height: 633px;
    overflow: hidden;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 6000;
}
.imageExpanded img {
    height: 630px;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 6000;
}

The javascript: JavaScript:

   jQuery(function ($) {
       $("div.hoverImage0").click(function () {
           $(this).css('cursor', 'pointer');
           $("div.overlayImage0").stop(true, true).css('visibility', 'visible');
       });
       $("div.hoverImage0").mouseleave(function () {
           $(this).css('cursor', 'default');
           $("div.overlayImage0").stop(true, true).css('visibility', 'hidden');
       });)
   };

I've figured, that the problem is in position property of .item 我已经知道,问题出在.item的 position属性中

So, if you put the line in comment 所以,如果您在注释中添加一行

.item {
    margin-bottom: 1em;
    -webkit-column-break-inside: avoid;
    -moz-column-break-inside: avoid;
    column-break-inside: avoid;
    border: 0px solid #000;
    overflow: visible;
/*  position: relative; */  <-- HERE
    z-index: 1000;
}

everything seems to be working fine in Chrome. Chrome似乎一切正常。

Here's the test: 这是测试:

 jQuery(function ($) { $("div.hoverImage0").click(function () { $(this).css('cursor', 'pointer'); $("div.overlayImage0").stop(true, true).css('visibility', 'visible'); }); $("div.hoverImage0").mouseleave(function () { $(this).css('cursor', 'default'); $("div.overlayImage0").stop(true, true).css('visibility', 'hidden'); }); }); 
 #wrapper { max-width: 80em; min-height: 66em; margin: 0 auto; position: relative; z-index: 1000; } #list { width: 100%; overflow: hidden; margin-bottom: .875em; -webkit-column-count: 3; -webkit-column-gap: 1em; -webkit-column-fill: auto; -moz-column-count: 3; -moz-column-gap: 1em; -moz-column-fill: auto; column-count: 3; column-gap: 1em; column-fill: auto; position: relative; z-index: 1000; } .item { margin-bottom: 1em; -webkit-column-break-inside: avoid; -moz-column-break-inside: avoid; column-break-inside: avoid; border: 0px solid #000; overflow: visible; /* position: relative;*/ z-index: 1000; } .tile { border: 2px solid #908094; -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; overflow: hidden; position: relative; z-index: 2000; } .mouse { position: absolute; top: 20px; right: 20px; z-index: 2000; } .hoverImage0 { position: relative; z-index: 2000; } .overlayImage0 { width: 1200px; height: 840px; position: absolute; top: 0; left: 0; transition:all 50ms ease-in-out 50ms; background: #000; overflow: visible; z-index: 5000; } .imageExpanded { width: 848px; height: 633px; overflow: hidden; position: absolute; top: 0; left: 0; z-index: 6000; } .imageExpanded img { height: 630px; position: absolute; top: 0; left: 0; z-index: 6000; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="wrapper"> <div id="list"> <div class="item"> <div class="tile bg0 hoverImage0"> <img src="http://skywalker.websight-dev.co.za/images/expand-icon.png" class="mouse" alt="Image is clickable" title="Image is clickable" /> <img src="http://skywalker.websight-dev.co.za/images/Image_Expandible.jpg" alt="W" /> </div> <div class="tile imageExpanded overlayImage0" style="visibility:hidden"> <img src="http://skywalker.websight-dev.co.za/images/Image_EXPANDED.jpg" alt="W" /> </div> </div> </div> </div> 

PS Of course, it's not the best way to fix it, because it looks like a bug (or some conflict between position, overflow and column-count), so maybe you should rebuild the markup. PS当然,这不是修复它的最佳方法,因为它看起来像是一个错误(或位置,溢出和列数之间的某些冲突),因此也许您应该重新构建标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM