Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange z-index behavior with scrollbars under Chrome

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.

like image 355
Vincent Batoufflet Avatar asked Jun 01 '13 15:06

Vincent Batoufflet


People also ask

How do I get rid of unnecessary scrollbar?

A quick fix is to add overflow: hidden to the CSS for your #footer . Note: A scrollbar will still appear if your #body content flows out of the the viewport. Show activity on this post. It will remove unnecessary scroll bars.

How do I inspect scrollbar in Chrome?

Chrome DevTools: Scroll elements into the viewportRight click on the DOM node from the elements panel. Select Scroll into view.

How do I fix the scrollbar in CSS?

The easy fix is to use width: 100% instead. Percentages don't include the width of the scrollbar, so will automatically fit. If you can't do that, or you're setting the width on another element, add overflow-x: hidden or overflow: hidden to the surrounding element to prevent the scrollbar.

What are overlay scrollbars?

We call those overlay scrollbars and they are either partially or fully transparent while sitting on top of the page content. In other words, unlike classic scrollbars that take up physical real estate on the screen, overlay scrollbars sit on top of the screen content.


2 Answers

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

like image 179
jackysee Avatar answered Sep 27 '22 21:09

jackysee


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; } 
like image 31
sinspiral Avatar answered Sep 27 '22 21:09

sinspiral