CSS Chrome 下带有滚动条的奇怪 z-index 行为

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16874546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:04:47  来源:igfitidea点击:

Strange z-index behavior with scrollbars under Chrome

cssgoogle-chromescrollbarz-index

提问by Vincent Batoufflet

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

在“固定”定位元素上使用 z-index CSS 属性在 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).

当 Firefox 和 Opera 浏览器给我期待的结果时,Chrome 似乎不尊重 z-index 属性,在红色覆盖上方显示滚动条(请参阅下面的代码和小提琴)。

HTML:

HTML:

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

CSS:

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/

示例:http: //jsfiddle.net/kvNFW/

OS: Apple Mac OS 10.8 Google Chrome: Version 27.0.1453.93

操作系统:Apple Mac OS 10.8 Google Chrome:版本 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 screenshotfor an overview of the issue.

有关问题的概述,请参阅此屏幕截图

回答by Hymanysee

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

您可以尝试添加-webkit-transform: translate3d(0, 0, 0). 它解决了我在移动 chrome 中发生的类似问题。

回答by sinspiral

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.

我遇到了一些类似的问题,我找到的唯一解决方法是对 webkit 滚动条应用一些特殊样式,以便始终显示它。请参阅http://jsfiddle.net/sinspiral/pTkQL/并修复您的示例。

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.

这与平台不兼容(因为在 Windows 上它也会应用这些样式),因此您可能需要找到一种方法,也许是 js,来检测它在哪个操作系统上运行。

.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;
}