28

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.

Vincent Batoufflet
  • 282
  • 1
  • 3
  • 7

2 Answers2

51

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

jackysee
  • 2,051
  • 4
  • 32
  • 38
  • 4
    Thanks for the tip.Indeed adding `-webkit-transform: translate3d(0, 0, 0)` on the yellow block did the trick. – Vincent Batoufflet Apr 05 '14 at 15:19
  • 5
    This seems to be an issue (again?) on Chrome 48 in combination with autohiding scrollbars in OS X. `translateZ(0)` fixes it. – chrisM Jan 27 '16 at 14:02
  • 1
    I run into the same issue in Chrome 48 as @chrisM said. Adding `transform: translateZ(0);` on the higher z-index element did the trick. Thanks – rmiguelrivero Feb 01 '16 at 12:24
  • thank you! I've been pulling my hair out trying to figure out what was going on with WordPress & Visual Composer. Adding this to the .vc_row class fixed the issue. – ryanka Nov 09 '17 at 19:21
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;
}
sinspiral
  • 21
  • 2
  • Indeed with these Webkit-specific styles the scrollbar goes in the background. But sadly it became always visible, no longer fading away when leaving the area. – Vincent Batoufflet Dec 21 '13 at 17:33