CSS background color is erased by scroll bar on Chrome browser
Asked Answered
E

1

3

I have a container with specified height, and inside it items are stacked. By default, I set overflow items as hidden and once mouse hover I enable the container to show scroll bar.
The HTML

#container {
  width: 200px;
  background-color: gray;
  height: 200px;
  overflow-y: hidden;
}
#container:hover {
  overflow-y: auto;
}
.item {
  margin-top: 2px;
  margin-bottom: 2px;
  background-color: yellow;
}
<div id="container">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
  <div class="item">Item 4</div>
  <div class="item">Item 5</div>
  <div class="item">Item 6</div>
  <div class="item">Item 7</div>
  <div class="item">Item 8</div>
  <div class="item">Item 9</div>
  <div class="item">Item 10</div>
</div>

It works as I wished except on Chrome browser after mouse moving out the container and scroll bar is disappear, the background color of scroll bar region is erased. This happens only on Chrome. Any idea?

Demo

Essa answered 26/11, 2013 at 8:13 Comment(0)
I
2

try this code:

DEMO

#container:hover .item{
    width:auto;
}

.item {
    margin-top:2px;
    margin-bottom: 2px;
    background-color: yellow;
    width:200px;
}

you can use 100% instead 200px too.

Ibo answered 26/11, 2013 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.