Strange z-index behavior with scrollbars under Chrome

北慕城南 提交于 2020-06-09 09:23:30

问题


Using z-index CSS property on 'fixed' positioned elements gives me a strange behavior under Chrome.

When Firefox and Opera browsers give me the awaited result, Chrome does not seem to respect the z-index property, displaying the scrollbar above the red overlay (see code and Fiddle bellow).

HTML:

<div class="left">
    <div class="placeholder"></div>
</div>
<div class="right"></div>
<div class="overlay"></div>

CSS:

.left {
    background-color: yellow;
    bottom: 0;
    left: 0;
    overflow: auto;
    position: fixed;
    top: 0;
    width: 35%;
    z-index: 10;
}

.right {
    background-color: orange;
    bottom: 0;
    position: fixed;
    right: 0;
    top: 0;
    width: 65%;
    z-index: 20;
}

.overlay {
    background-color: red;
    bottom: 20%;
    left: 25%;
    position: fixed;
    right: 25%;
    top: 20%;
    z-index: 40;
}

.placeholder {
    height: 3000px;
}

Example: http://jsfiddle.net/kvNFW/

OS: Apple Mac OS 10.8 Google Chrome: Version 27.0.1453.93

Is there someone having experienced the same issues, or having a way to fix that?

Thanks in advance for any help.

Edit:

See this screenshot for an overview of the issue.


回答1:


You may try to add -webkit-transform: translate3d(0, 0, 0). It solves my similar problem happened in mobile chrome.




回答2:


I had some similar issues, and the only way to resolve I found was to apply some special styles to the webkit scrollbar in order to show it always. See http://jsfiddle.net/sinspiral/pTkQL/ with your example fixed.

This is not platform compatible (as on windows it will apply those styles too), so you might need to find a way, maybe js, to detect on which OS it is running.

.left::-webkit-scrollbar{
   -webkit-appearance: none;
}

.left::-webkit-scrollbar-thumb {
    background-color: rgba(50, 50, 50, .5);
    border: 3px solid transparent;
    border-radius: 9px;
    background-clip: content-box;
}

.left::-webkit-scrollbar-track {
    background-color: rgba(100, 100, 100, .5);
    width: 15px;
}


来源:https://stackoverflow.com/questions/16874546/strange-z-index-behavior-with-scrollbars-under-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!