【发布时间】:2021-04-10 07:01:23
【问题描述】:
我想编写这样设计的滚动条:
这意味着-webkit-scrollbar-thumb 的宽度必须5px 和-webkit-scrollbar-track 的宽度必须2px 但我不能改变-webkit-scrollbar-track 的宽度独立于-webkit-scrollbar-thumb。
.main {
width: 100px;
height: 100px;
max-height: 100px;
background-color: #fff;
border: 1px solid red;
overflow-y: auto;
}
/* Scrollbar */
/* width */
::-webkit-scrollbar {
width: 5px;
height: 5px;
}
/* Track */
::-webkit-scrollbar-track {
background: #dddddd;
/*box-shadow: inset 0 0 5px #dddddd;*/
border-radius: 4px;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #9e9e9e;
border-radius: 4px;
}
<div class="main">
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div>test</div>
</div>
【问题讨论】:
-
嗨,你有没有检查过哪个浏览器支持
-webkit-scrollbar-track??比如火狐不支持 -
你好,是的,我检查了 chrome 并且没问题。但
-webkit-scrollbar-track的宽度不会改变。 -
在你的css中你忘记为
-webkit-scrollbar-truck设置width: 2px; -
我设置但没有改变任何东西。你测试了吗?
-
我现在无法检查,因为我使用的是 Firefox,而且我在 Ubuntu 上,抱歉。但我会尝试一些东西