html - CSS:如何根据 class/id 自定义滚动条填充和边距
问题描述
我想要三种不同类型的滚动条,其填充和边距不同。下面是我的滚动条的全局样式:
/*
Modifying the scroll bar across the whole application
*/
/* width */
::-webkit-scrollbar {
width: 5px;
height: 5px;
}
/* Track */
::-webkit-scrollbar-track {
border-radius: 10px;
width: 5px;
height: 5px;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #999999 !important;
border-radius: 10px;
}
::-webkit-scrollbar-track {
background: #d1d1d1 !important;
border: 1px solid #ebebeb !important;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #b30000;
}
现在我想使用类名或 id 使用具有不同填充和边距的滚动条。我不希望滚动条填充和边距影响滚动条中内容的填充和边距。我怎样才能以这种方式编写css,这将为每个滚动条放置不同的填充。
解决方案
您可以像使用 css 选择元素一样选择该元素。
选择容器 div 并像这样添加您的规则
<div class="container">
<div class="innerdiv"></div>
</div>
.container {
height: 300px;
width: 300px;
overflow-y: scroll;
}
.container .innerdiv {
height: 600px;
background:blue;
}
.container::-webkit-scrollbar {
width: 3px;
}
.container::-webkit-scrollbar-thumb {
background: black;
}
.container::-webkit-scrollbar-track {
background: red;
}
这是一个工作示例-> https://jsfiddle.net/2fzpoycv/
推荐阅读
- python - 如何将文件移动到新文件夹
- c# - 触发事件时在函数调用中引发异常
- javascript - VueJs 输入文件 @change 在第一次调用 chrome 后执行
- angular - 如何自定义 mat-calendar-header 以添加时间选择器
- java - 如何在请求参数spring中使用对象对url字符串进行编码
- java - UncaughtExceptionHandler 有时不起作用
- java - 如何在java流过滤器中使用java流映射
- javascript - 将项目放入网格和相邻框中的更干净的方法?
- batch-file - 我想在没有 Windows 任务计划程序的情况下计划批处理文件
- c - 求 2 名学生的平均值