CSS background color is erased by scroll bar on Chrome browser

99封情书 提交于 2019-12-12 14:39:07

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/20211644/css-background-color-is-erased-by-scroll-bar-on-chrome-browser

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