0

When I set overflow: scroll to a div, I'm expecting to have a scrollbar even when the content doesn't scroll (for design purposes)

but when there's no need to scroll, chrome mobile hides the scrollbar anyway.

.div-scroll{
  background-color: red;
  height: 300px;
  overflow-y: scroll;
}
.div-inner {
  background-color: blue;
  height: 200px;
}
<div class="div-scroll">
  <div class="div-inner">
  </div>
</div>

I'd like to show a disabled scroll on Chrome Mobile when the content doesn't scroll, or at least a way to know from pure CSS that it doesn't scroll, to avoid using width: calc(100% - 17px);

Fiddle

4

1 回答 1

2

在 webkit 浏览器上有一个永久滚动条,您可以使用这些::webkit-scrollbar ::webkit-scrollbar-thumb属性并自定义它们。

参考以下代码:

.filter-list {
  width: 75px;
  height: 100px;
  overflow: auto;
}

.filter-list::-webkit-scrollbar,
.filter-list::-webkit-scrollbar,
.filter-list::-webkit-scrollbar {
  -webkit-appearance: none;
  width: 15px;
}

.filter-list::-webkit-scrollbar-thumb,
.filter-list::-webkit-scrollbar-thumb,
.filter-list::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background-color: lightgray;
  box-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
}
<div class="filter-list">
  <div> Hello </div>
  <div> World </div>
  <div> Hello </div>
  <div> World </div>
  <div> Hello </div>
  <div> World </div>
  <div> Hello </div>
  <div> World </div>
  <div> Hello </div>
  <div> World </div>
</div>

于 2017-02-21T13:07:05.747 回答